diff --git a/linker-files/module.scm b/linker-files/module.scm index 81c846b..fd7c619 100644 --- a/linker-files/module.scm +++ b/linker-files/module.scm @@ -1,19 +1,19 @@ -(define memories - '((memory zeroPage (address (#x56 . #xff)) (type ram) - (section registers zpage zzpage)) - (memory firstPage (address (#x100 . #x1ff)) (section stack)) - (memory reserved (address (#x200 . #x1fff)) (type ram)) - (memory displayPage1 (address (#x2000 . #x3fff)) (type ram)) - (memory upperProg (address (#x4000 . #x93ff)) (type ram) (section (programStart #x4000) startup code switch idata cdata data_init_table)) - (memory upperData (address (#x9400 . #x99ff)) (type ram) (section cstack zdata data heap)) - (memory sharedMem (address (#x9a00 . #x9bff)) (type ram)) ;;; This memory page will be used to pass parameters and data between the master and the modules, and to save the game state - (memory diskBuffer (address (#x9c00 . #x9eff)) (type ram)) - (memory zeroPageBackup (address (#x9f00 . #x9fff)) (type ram) (section (zpsave #x9f00))) - (memory displayPage2 (address (#xa000 . #xbfff)) (type ram)) - (memory io (address (#xc000 . #xc0ff)) (type ram)) - (memory rombank (address (#xc100 . #xffff)) (type rom)) - - (block cstack (size #x400)) - (block heap (size #x020)) - (block stack (size #x100)) +(define memories + '((memory zeroPage (address (#x56 . #xff)) (type ram) + (section registers zpage zzpage)) + (memory firstPage (address (#x100 . #x1ff)) (section stack)) + (memory reserved (address (#x200 . #x1fff)) (type ram)) + (memory displayPage1 (address (#x2000 . #x3fff)) (type ram)) + (memory upperProg (address (#x4000 . #x935f)) (type ram) (section (programStart #x4000) startup code switch idata cdata data_init_table)) + (memory upperData (address (#x9360 . #x99ff)) (type ram) (section cstack zdata data heap intrzp)) + (memory sharedMem (address (#x9a00 . #x9bff)) (type ram)) ;;; This memory page will be used to pass parameters and data between the master and the modules, and to save the game state + (memory diskBuffer (address (#x9c00 . #x9eff)) (type ram)) + (memory zeroPageBackup (address (#x9f00 . #x9fff)) (type ram) (section (zpsave #x9f00))) + (memory displayPage2 (address (#xa000 . #xbfff)) (type ram)) + (memory io (address (#xc000 . #xc0ff)) (type ram)) + (memory rombank (address (#xc100 . #xffff)) (type rom)) + + (block cstack (size #x400)) + (block heap (size #x020)) + (block stack (size #x100)) )) \ No newline at end of file diff --git a/linker-files/vdpin_module.scm b/linker-files/vdpin_module.scm index 363b002..2a0f734 100644 --- a/linker-files/vdpin_module.scm +++ b/linker-files/vdpin_module.scm @@ -5,7 +5,7 @@ (memory reserved (address (#x200 . #x1fff)) (type ram)) (memory displayPage1 (address (#x2000 . #x3fff)) (type ram)) (memory upperProg (address (#x4000 . #x7fff)) (type ram) (section (programStart #x4000) startup code switch idata cdata data_init_table)) - (memory upperData (address (#x8000 . #x99ff)) (type ram) (section cstack zdata data heap)) + (memory upperData (address (#x8000 . #x99ff)) (type ram) (section cstack zdata data heap intrzp)) (memory sharedMem (address (#x9a00 . #x9bff)) (type ram)) ;;; This memory page will be used to pass parameters and data between the master and the modules, and to save the game state (memory diskBuffer (address (#x9c00 . #x9eff)) (type ram)) (memory zeroPageBackup (address (#x9f00 . #x9fff)) (type ram) (section (zpsave #x9f00))) diff --git a/src/vddem_main.c b/src/vddem_main.c index 298b4f3..398c3ab 100644 --- a/src/vddem_main.c +++ b/src/vddem_main.c @@ -43,8 +43,6 @@ static uint8_t text_buf[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static volatile uint8_t key_pressed = 0; -__attribute__((interrupt)) void irq_handler(void); - void main(void) { uint16_t moves_count = 0; uint16_t score = 0; @@ -65,7 +63,7 @@ void main(void) { vdp_switch_nt(0); // Make sure VDP shows the gamegrid // Setup the IRQ handler - POKEW(IRQ_HANDLER_ADDRESS, (uint16_t)irq_handler); + POKEW(IRQ_HANDLER_ADDRESS, (uint16_t)vdp_irq_handler); // Reset the game, calculate the initial score depending on which tiles we randomly get score = reset_game(); @@ -192,7 +190,3 @@ void main(void) { return; } - -__attribute__((interrupt)) void irq_handler(void) { - vdp_write_interleaved_sat(); -} diff --git a/src/vddlg_main.c b/src/vddlg_main.c index e94c01e..acd087f 100644 --- a/src/vddlg_main.c +++ b/src/vddlg_main.c @@ -64,6 +64,13 @@ void main(void) { if(dld->score > state_page->hi_score) { // New high-score. We need to save it. state_page->hi_score = dld->score; + + // Update the score! + num_to_decbuf(state_page->hi_score, 6, score_buf); + decbuf_to_ascii(6, score_buf); + vdp_print_string(1, 13, 12, (char*)score_buf); + vdp_print_string(1, 8, 13, "!NEW HIGH SCORE!"); + shared_page->master_command = MASTER_COMMAND_SAVE; } else { shared_page->master_command = MASTER_COMMAND_NONE; diff --git a/src/vdgam_main.c b/src/vdgam_main.c index a91e088..328e152 100644 --- a/src/vdgam_main.c +++ b/src/vdgam_main.c @@ -39,8 +39,6 @@ static state_page_data* state_page = (state_page_data*)STATE_PAGE; static shared_page_data *shared_page = (shared_page_data*)SHARED_PAGE; static uint8_t text_buf[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -__attribute__((interrupt)) void irq_handler(void); - void main(void) { uint16_t moves_count = 0; uint16_t score = 0; @@ -61,7 +59,7 @@ void main(void) { vdp_switch_nt(0); // Make sure VDP shows the gamegrid // Setup the IRQ handler - POKEW(IRQ_HANDLER_ADDRESS, (uint16_t)irq_handler); + POKEW(IRQ_HANDLER_ADDRESS, (uint16_t)vdp_irq_handler); // Reset the game, calculate the initial score depending on which tiles we randomly get score = reset_game(); @@ -193,8 +191,3 @@ void main(void) { return; } - -__attribute__((interrupt)) void irq_handler(void) { - vdp_write_interleaved_sat(); -} - diff --git a/src/vdp_utils.h b/src/vdp_utils.h index b25a1ba..a033dcc 100644 --- a/src/vdp_utils.h +++ b/src/vdp_utils.h @@ -15,5 +15,6 @@ void vdp_switch_nt(uint8_t nt_idx); void vdp_print_string(uint8_t nt_idx, uint8_t x, uint8_t y, char *str); void vdp_set_tile(uint8_t nt_idx, uint8_t x, uint8_t y, uint8_t tile_idx); void vdp_write_interleaved_sat(void); +void vdp_irq_handler(void); #endif /* _VDP_UTILS_HEADER_ */ diff --git a/src/vdp_utils.s b/src/vdp_utils.s index 10e33be..753ad07 100644 --- a/src/vdp_utils.s +++ b/src/vdp_utils.s @@ -4,6 +4,10 @@ .extern _Zp .extern VDP_MEM, VDP_REG + ;;; Define a space + .section intrzp, noinit, root ; root, as we always require it + .space 0xA9 + .section code,text @@ -438,9 +442,6 @@ T_DLEN_H$: .equ _Zp+3 T_DLEN_L$: .equ _Zp+2 T_DATA_H$: .equ _Zp+1 T_DATA_L$: .equ _Zp+0 - lda VDP_REG ; FIXME: Put this here temporarily as this is often - ; used in interrupt handling, and we need to clear - ; the interrupt lda #0x00 sta zp:T_DEST_L$ @@ -490,6 +491,59 @@ WriteLoop$: rts +_irq_save_zp: + ldx #0 + +SaveZp$: + lda zp:_Zp,x + sta .sectionStart intrzp,x + inx + ;cpx #.sectionSize intrzp + cpx #10 ; Save only part of the ZP, we're not using more + bne SaveZp$ + + rts + +_irq_restore_zp: + ldx #0 + +RestoreZp$: + lda .sectionStart intrzp,x + sta zp:_Zp,x + inx + ;cpx #.sectionSize intrzp + cpx #10 ; Restpre only part of the ZP, we're not using more + bne RestoreZp$ + + rts + +vdp_irq_handler: + ; Save the registers + pha + txa + pha + tya + pha + + ;;; Save ZP + jsr _irq_save_zp + + lda VDP_REG + + jsr vdp_write_interleaved_sat + + ;;; Restore ZP + jsr _irq_restore_zp + + ; Restore the registers + pla + tay + pla + tax + pla + + rti + ;;;;;;;;;;;;;;;;;; .section data,data @@ -604,6 +658,7 @@ CurrentByteTableOffset: .public vdp_set_tile .public vdp_point_to_vram_xy .public vdp_write_interleaved_sat + .public vdp_irq_handler .public SpriteAttributeTable ; We'll need to set change visibility and values .public NT_P0, NT_P1 \ No newline at end of file