temporarely move every static data in the lower memory

This commit is contained in:
hkz 2025-07-17 16:04:58 +02:00
commit 340a521b05
5 changed files with 46 additions and 28 deletions

View file

@ -4,12 +4,11 @@
(memory firstPage (address (#x100 . #x1ff)) (section stack))
(memory reserved (address (#x200 . #x7ff)) (type ram))
(memory program (address (#x801 . #x1fff)) (type ram)
(section (programStart #x801) (startup #x80e) code))
(section (programStart #x801) (startup #x80e) code switch idata cdata data_init_table))
;;; (section (programStart #x801) (startup #x80e) code))
(memory displayPage1 (address (#x2000 . #x3fff)) (type ram))
;;; (memory datamem (address (#x4000 . #x91ff)) (type ram) (section cstack zdata heap)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it
;;; (memory upperData (address (#x9200 . #x9fff)) (section switch idata cdata data data_init_table))
(memory datamem (address (#x4000 . #x91ff)) (type ram) (section cstack zdata data heap)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it
(memory upperData (address (#x9200 . #x9fff)) (section switch idata cdata data_init_table))
;;;(memory upperData (address (#x9200 . #x9fff)) (type ram) (section switch idata cdata data_init_table))
(memory displayPage2 (address (#xa000 . #xbfff)) (type ram))
(memory io (address (#xc000 . #xc0ff)) (type ram))
(memory rombank (address (#xc100 . #xffff)) (type rom))

View file

@ -8,17 +8,17 @@
#include "game_logic.h"
#define SCREEN_WIDTH_B 40
#define TILE_SIDE 28
#define TILE_SIDE 35
#define TOP_OFFSET 14 // Top is offset by 14 lines
#define TOP_OFFSET 11 // Top is offset by 11 lines
#define LEFT_OFFSET_B 1 // Left is offset by 1 bytes (7 pixels)
static uint8_t *front_buf = (uint8_t*)DISPLAY_PAGE_1;
static uint8_t *back_buf = (uint8_t*)DISPLAY_PAGE_1;
// The grid is 5x5 squares,
// It is offset on the left side by 7 pixels and on the top by 14
// Every square is 28x28 pixels
// It is offset on the left side by 7 pixels and on the top by 11
// Every square is 35x35 pixels
void swap_display_buffers(void);
@ -27,19 +27,15 @@ void draw_game_background(void) {
uint8_t* buf = (uint8_t*)DISPLAY_PAGE_1;
// Horizontal borders
for(uint8_t col = 0; col < GRID_SIDE * 4; col++) {
for(uint8_t col = 0; col < GRID_SIDE * 5; col++) {
buf[line_offset_map[TOP_OFFSET] + col + LEFT_OFFSET_B] = 0x7F;
buf[line_offset_map[TOP_OFFSET + (TILE_SIDE * GRID_SIDE)] + col + LEFT_OFFSET_B] = 0x7F;
}
// vertical borders
for(uint8_t col = 0; col < GRID_SIDE * 4; col++) {
buf[line_offset_map[TOP_OFFSET] + col + LEFT_OFFSET_B] = 0x7F;
buf[line_offset_map[TOP_OFFSET + (TILE_SIDE * GRID_SIDE)] + col + LEFT_OFFSET_B] = 0x7F;
}
// TODO vertical borders
// Copy the data from display page 1 to 2
memcpy((void*)DISPLAY_PAGE_1, (void*)DISPLAY_PAGE_2, DISPLAY_PAGE_SIZE);
memcpy((void*)DISPLAY_PAGE_2, (void*)DISPLAY_PAGE_1, DISPLAY_PAGE_SIZE);
}

View file

@ -3,18 +3,34 @@
#include "utility.h"
#include "mem_registers.h"
key read_kb(void) {
key __internal_read_kb(void);
inline key __internal_read_kb(void) {
PEEK(IO_KB_CTRL_LOW);
POKE(IO_DATAOUT, 0x40);
if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_UP;
if (PEEK(IO_DATAIN) & 0x01) return K_UP;
POKE(IO_DATAOUT, 0x20);
if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_DOWN;
if (PEEK(IO_DATAIN) & 0x01) return K_DOWN;
POKE(IO_DATAOUT, 0x10);
if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_RIGHT;
if (PEEK(IO_DATAIN) & 0x01) return K_RIGHT;
POKE(IO_DATAOUT, 0x08);
if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_LEFT;
if (PEEK(IO_DATAIN) & 0x01) return K_LEFT;
return K_NONE;
return K_NONE;
}
key read_kb(void) {
static key last_press = K_NONE;
key cur_press = __internal_read_kb();
if (cur_press != last_press) {
last_press = cur_press;
return cur_press;
} else {
return K_NONE;
}
}

View file

@ -9,11 +9,12 @@
#include "input.h"
#include "game_logic.h"
#include "game_graphics.h"
#include "monitor_subroutines.h"
void __low_level_init(void);
void init(void);
// Low level initialization
void __low_level_init(void) {
void init(void) {
POKE(P3_PWRDUP, 0); // Dirty the value checked by the reset vector
PEEK(IO_ROMSEL); // Make sure the ROM is selected
@ -26,6 +27,8 @@ void __low_level_init(void) {
}
__task int main(void) {
init();
game_state state;
while(1){ // Outer loop
@ -37,15 +40,19 @@ __task int main(void) {
switch(read_kb()) {
case K_UP:
BELL1();
state = step_game(UP);
break;
case K_DOWN:
BELL1();
state = step_game(DOWN);
break;
case K_LEFT:
BELL1();
state = step_game(LEFT);
break;
case K_RIGHT:
BELL1();
state = step_game(RIGHT);
break;
default:
@ -62,6 +69,6 @@ __task int main(void) {
}
};
return 0;
}

View file

@ -87,10 +87,10 @@ __call_heap_initialize:
;;;
;;; ***************************************************************************
;;; .section code
;;; .pubweak __low_level_init
;;;__low_level_init:
;;; rts
.section code
.pubweak __low_level_init
__low_level_init:
rts
;;; ***************************************************************************
;;;