mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 14:22:16 +11:00
Rewritten the irq handler
This commit is contained in:
parent
2999c7c218
commit
46f3662322
7 changed files with 87 additions and 37 deletions
|
|
@ -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))
|
||||
))
|
||||
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue