From 7c4385972d9bfb2c246b14c11643beed164cdd0a Mon Sep 17 00:00:00 2001 From: hkz Date: Mon, 13 Oct 2025 17:24:13 +0200 Subject: [PATCH] Begin fixing game code --- src/game_vdp_graphics.s | 46 ++++++++++++++++++++++++++++++++++------- src/vdgam_main.c | 37 +++++++++++++++++---------------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/game_vdp_graphics.s b/src/game_vdp_graphics.s index f0e9352..e5ad36e 100644 --- a/src/game_vdp_graphics.s +++ b/src/game_vdp_graphics.s @@ -32,9 +32,6 @@ SetSprtLoop$: pla jmp SkipSprite$ SkipHide$: - pla - tay - pla sta zp:_Zp+0 dec zp:_Zp+0 tya @@ -49,7 +46,24 @@ SkipHide$: SkipSprite$: dey bpl SetSprtLoop$ + + ldy #24 +SetTileLoop$: + tya + pha + lda TileNum_To_X_Map,y + sta zp:_Zp+0 + lda TileNum_To_Y_Map,y + sta zp:_Zp+1 + lda (zp:P_GRID_L$),y + jsr vdp_draw_numtile + + pla + tay + dey + bpl SetTileLoop$ + rts vdp_draw_joystick: @@ -58,9 +72,10 @@ P_POS$: .equ _Zp+2 T_Y$: .equ _Zp+1 T_X$: .equ _Zp+0 + pha + ldx #0 stx zp:T_NT_IDX$ - pha ; Clear the table lda #29 @@ -221,11 +236,11 @@ P_X$: .equ _Zp+0 ; Convert the coordinates ldx zp:P_X$ - lda TileNum_X_Map,x + lda X_To_TileNum_Map,x sta zp:P_X$ ldx zp:P_Y$ - lda TileNum_Y_Map,x + lda Y_To_TileNum_Map,x sta zp:P_Y$ ; Calculate the beginning of the tile section we're interested in @@ -268,11 +283,26 @@ TileNum_Offset_Map: ; Offset from the beginning of the selected tilemap section, .byte 0x01, 0x04, 0x04, 0x03 ; Third and last ; The following maps convert between X and Y in the game grid into the tile map grid -TileNum_X_Map: +X_To_TileNum_Map: .byte 0x01, 0x06, 0x0B, 0x10, 0x15 -TileNum_Y_Map: +Y_To_TileNum_Map: .byte 0x01, 0x05, 0x09, 0x0D, 0x11 +; The following maps convert between the tile number and the corresponding X and Y coordinates +TileNum_To_X_Map: + .byte 0x00, 0x01, 0x02, 0x03, 0x04 + .byte 0x00, 0x01, 0x02, 0x03, 0x04 + .byte 0x00, 0x01, 0x02, 0x03, 0x04 + .byte 0x00, 0x01, 0x02, 0x03, 0x04 + .byte 0x00, 0x01, 0x02, 0x03, 0x04 + +TileNum_To_Y_Map: + .byte 0x00, 0x00, 0x00, 0x00, 0x00 + .byte 0x01, 0x01, 0x01, 0x01, 0x01 + .byte 0x02, 0x02, 0x02, 0x02, 0x02 + .byte 0x03, 0x03, 0x03, 0x03, 0x03 + .byte 0x04, 0x04, 0x04, 0x04, 0x04 + ;;;;;;;;;;;;;;;;;; .public vdp_draw_numtile .public vdp_clear_gamegrid diff --git a/src/vdgam_main.c b/src/vdgam_main.c index 08c0e76..d511f58 100644 --- a/src/vdgam_main.c +++ b/src/vdgam_main.c @@ -28,16 +28,16 @@ #define HSCORE_TEXT_Y 13 #define SCORE_TEXT_X 27 -#define SCORE_TEXT_Y 8 +#define SCORE_TEXT_Y 4 #define MOVES_TEXT_X 27 -#define MOVES_TEXT_Y 4 +#define MOVES_TEXT_Y 8 #define WIN_SCORE_BONUS 10000 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[7] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static uint8_t text_buf[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; void main(void) { uint16_t moves_count = 0; @@ -77,21 +77,22 @@ void main(void) { } // Draw the initial state of the game - num_to_decbuf(state_page->hi_score, 6, text_buf); // High score - decbuf_to_ascii(6, text_buf); + num_to_decbuf(state_page->hi_score, 5, text_buf); // High score + decbuf_to_ascii(5, text_buf); vdp_print_string(0, HSCORE_TEXT_X, HSCORE_TEXT_Y, (char*)text_buf); - num_to_decbuf(moves_count, 6, text_buf); // Moves count - decbuf_to_ascii(6, text_buf); + num_to_decbuf(moves_count, 5, text_buf); // Moves count + decbuf_to_ascii(5, text_buf); vdp_print_string(0, MOVES_TEXT_X, MOVES_TEXT_Y, (char*)text_buf); - num_to_decbuf(score, 6, text_buf); // Score - decbuf_to_ascii(6, text_buf); + num_to_decbuf(score, 5, text_buf); // Score + decbuf_to_ascii(5, text_buf); vdp_print_string(0, SCORE_TEXT_X, SCORE_TEXT_Y, (char*)text_buf); - vdp_draw_joystick(JS_POS_CENTER); // Center the joystick + //vdp_draw_joystick(JS_POS_CENTER); // Center the joystick - vdp_redraw_tiles(get_front_grid()); + //vdp_redraw_tiles(get_front_grid()); + while(1); __enable_interrupts(); @@ -99,7 +100,7 @@ void main(void) { lfsr_update(); __disable_interrupts(); - vdp_draw_joystick(JS_POS_CENTER); + //vdp_draw_joystick(JS_POS_CENTER); __enable_interrupts(); switch(read_kb()) { @@ -107,28 +108,28 @@ void main(void) { SND_TAP(); done = step_game(GAME_STEP_UP); __disable_interrupts(); - vdp_draw_joystick(JS_POS_UP); + //vdp_draw_joystick(JS_POS_UP); __enable_interrupts(); break; case K_DOWN: SND_TAP(); done = step_game(GAME_STEP_DOWN); __disable_interrupts(); - vdp_draw_joystick(JS_POS_DOWN); + //vdp_draw_joystick(JS_POS_DOWN); __enable_interrupts(); break; case K_LEFT: SND_TAP(); done = step_game(GAME_STEP_LEFT); __disable_interrupts(); - vdp_draw_joystick(JS_POS_LEFT); + //vdp_draw_joystick(JS_POS_LEFT); __enable_interrupts(); break; case K_RIGHT: SND_TAP(); done = step_game(GAME_STEP_RIGHT); __disable_interrupts(); - vdp_draw_joystick(JS_POS_RIGHT); + //vdp_draw_joystick(JS_POS_RIGHT); __enable_interrupts(); break; case K_CTRL_R: @@ -186,14 +187,14 @@ void main(void) { decbuf_to_ascii(6, text_buf); __disable_interrupts(); vdp_print_string(0, SCORE_TEXT_X, SCORE_TEXT_Y, (char*)text_buf); - vdp_redraw_tiles(get_front_grid()); + //vdp_redraw_tiles(get_front_grid()); __enable_interrupts(); } dld->mode = (done > 0) ? DLOG_MODE_WIN : DLOG_MODE_LOSE; dld->score = score; - vdp_redraw_tiles(get_front_grid()); + //vdp_redraw_tiles(get_front_grid()); WAIT(0xFF);