diff --git a/source/charmap.inc b/source/charmap.inc index e899243..fdc0866 100644 --- a/source/charmap.inc +++ b/source/charmap.inc @@ -1,5 +1,3 @@ -; vim:set syn=asm: - if 0 ;!def(_charmap_inc_) _charmap_inc_ equ 0 diff --git a/source/hardware.inc b/source/hardware.inc index 96dba15..4fd18b4 100644 --- a/source/hardware.inc +++ b/source/hardware.inc @@ -89,6 +89,10 @@ r_stat_mode_vram equ 3 << r_stat_mode_f r_ly equ $ff44 r_ly_vblank equ 144 +r_bgp equ $ff47 +r_obp0 equ $ff48 +r_obp1 equ $ff49 + rsreset r_bcps equ $ff68 bits r_bcps_offs, 3 diff --git a/source/home/start.asm b/source/home/start.asm index 13f5cbb..46c9f36 100644 --- a/source/home/start.asm +++ b/source/home/start.asm @@ -2,7 +2,7 @@ include "hardware.inc" include "defines.inc" NULL equ 0 -global NULL +export NULL section "home/start.asm@wram0", wram0 ds $100 - 1 @@ -36,7 +36,7 @@ _start: .console_cgb dec b - jr z, .console_agb + jr z, .console_end dec c ; console_cgb .console_end @@ -55,23 +55,22 @@ if def(ENABLE_CLEAR) endc ld sp, w_stack - ldh a, [h_console] - push af if def(ENABLE_CLEAR) ; Clear the hram and wram1 + ldh a, [h_console] + push af xor a ld hl, mmap_hram ld bc, mmap_hram_end - mmap_hram call memset + pop af + ldh [h_console], a ld hl, mmap_wramx ld bc, mmap_wramx_end - mmap_wramx call memset endc - pop af - ldh [h_console], a - if def(ENABLE_CGB) && def(ENABLE_CLEAR) ; Clear the different wram banks cp console_cgb @@ -93,6 +92,11 @@ if def(ENABLE_CGB) && def(ENABLE_CLEAR) .end endc + call audio_disable +if def(ENABLE_CLEAR) + call vram_clear +endc + ei jp main diff --git a/source/home/text.asm b/source/home/text.asm index d0c86c6..335cf54 100644 --- a/source/home/text.asm +++ b/source/home/text.asm @@ -1,4 +1,21 @@ include "charmap.inc" +include "video.inc" + +section "home/text.asm@data", rom0 +gfx_font: +incbin "assets/tetrisfont.1bpp" +.end + +section "home/text.asm@vram", vram + +ds $2D tiles +v_font_dash_period: ds 2 tiles +ds $1 tiles +v_font_numbers: ds 10 tiles +ds $7 tiles +v_font_uppercase: ds 26 tiles +ds $6 tiles +v_font_lowercase: ds 26 tiles section "home/text.asm", rom0 @@ -40,3 +57,22 @@ print_num_3digit:: dec l jr nz, .loop ret + +font_load:: + ld hl, gfx_font + ld de, v_font_numbers + ld bc, (10 tiles) / 2 + call memcpy_double + ld de, v_font_uppercase + ld bc, (26 tiles) / 2 + call memcpy_double + ld hl, gfx_font + (10 tiles) / 2 + ld de, v_font_lowercase + ld bc, (26 tiles) / 2 + call memcpy_double + ld de, v_font_dash_period + (1 tiles) + ld bc, (1 tiles) / 2 + call memcpy_double + ld de, v_font_dash_period + ld bc, (1 tiles) / 2 + jp memcpy_double diff --git a/source/home/video.asm b/source/home/video.asm index 6a6600a..720eebb 100644 --- a/source/home/video.asm +++ b/source/home/video.asm @@ -52,3 +52,46 @@ vram_clear:: ld hl, mmap_oam ld bc, mmap_oam_end - mmap_oam jp memset + +vram_clear_bgmap:: + xor a + ld hl, v_bgmap1 + ld bc, bgmap_width * bgmap_height + jp memset + +; Set black/white palettes +pals_set_bw:: +if def(ENABLE_CGB) + ldh a, [h_console] + cp console_cgb + jr c, .dmg + + ld a, r_bcps_inc | 0 << r_bcps_pal_f | 0 << r_bcps_offs_f + ld c, LOW(r_bcps) + ldh [c], a + inc c + ld hl, .pal_bw + ld b, 8 +.loop_pal_1 + ld a, [hl+] + ldh [c], a + dec b + jr nz, .loop_pal_1 + ret +endc + +.dmg + ld a, $e4 + ld hl, r_bgp + ld [hl+], a ; r_bgp + ld [hl+], a ; r_obp0 + ld [hl+], a ; r_obp1 + ret + +if def(ENABLE_CGB) +.pal_bw + dw $7fff + dw $5294 + dw $294a + dw $0000 +endc diff --git a/source/main.asm b/source/main.asm index 50c93dd..d98159f 100644 --- a/source/main.asm +++ b/source/main.asm @@ -1,127 +1,22 @@ include "charmap.inc" include "defines.inc" include "video.inc" -include "hardware.inc" - -section "main.asm@data", rom0 -gfx_font: -incbin "assets/tetrisfont.1bpp" -gfx_font_end: - -section "main.asm@vram", vram - -ds $2D tiles -v_font_dash_period: ds 2 tiles -ds $1 tiles -v_font_numbers: ds 10 tiles -ds $7 tiles -v_font_uppercase: ds 26 tiles -ds $6 tiles -v_font_lowercase: ds 26 tiles section "main.asm", rom0 main:: - call audio_disable call lcd_disable -if def(ENABLE_CLEAR) - call vram_clear -endc - - ; Load the font - ld hl, gfx_font - ld de, v_font_numbers - ld bc, (10 tiles) / 2 - call memcpy_double - ld de, v_font_uppercase - ld bc, (26 tiles) / 2 - call memcpy_double - ld hl, gfx_font + (10 tiles) / 2 - ld de, v_font_lowercase - ld bc, (26 tiles) / 2 - call memcpy_double - ld de, v_font_dash_period + (1 tiles) - ld bc, (1 tiles) / 2 - call memcpy_double - ld de, v_font_dash_period - ld bc, (1 tiles) / 2 - call memcpy_double - - ; Setup the palettes -if def(ENABLE_CGB) - ldh a, [h_console] - cp console_cgb - jr c, .skip_pals - - ld a, r_bcps_inc | 0 << r_bcps_pal_f | 0 << r_bcps_offs_f - ld c, LOW(r_bcps) - ldh [c], a - inc c - ld b, 4 - ld a, $ff -.loop_pal_1 - ldh [c], a - dec b - jr nz, .loop_pal_1 - ld b, 4 - xor a -.loop_pal_2 - ldh [c], a - dec b - jr nz, .loop_pal_2 - -.skip_pals -endc - - ; Clear the background map - xor a - ld hl, v_bgmap1 - ld bc, bgmap_width * bgmap_height - call memset - + call font_load + call pals_set_bw + ;call vram_clear_bgmap call lcd_enable + ld hl, string_something - bgcoord de, 5, 2 + bgcoord de, (screen_width - string_something.end + string_something + 1) / 2, 2 call print - call serial_init_master - -main_loop: - call joypad_update - bit joy_a_f, a - jr nz, .send_shit - - bgcoord hl, 7, 5 - call lcd_blank_wait - ld [hl], " " - -.continue - call vblank_wait - jr main_loop - -.send_shit - call vblank_wait - call joypad_update - bit joy_a_f, a - jr nz, .send_shit - - bgcoord hl, 7, 5 - call lcd_blank_wait - ld [hl], "A" - ld hl, transfer_buffer - ld de, NULL - ld bc, transfer_buffer.end - transfer_buffer - call serial_transfer - -.send_shit_wait - call vblank_wait - call serial_finished - jr nz, .send_shit_wait - - jr .continue - -transfer_buffer: -db $00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $AA, $BB, $CC, $DD, $EE, $FF -.end + ;call prog_serial_test + jp _halt_ string_something: db "SOMETHING$" +.end diff --git a/source/prog/serial_test.asm b/source/prog/serial_test.asm new file mode 100644 index 0000000..9ea4a10 --- /dev/null +++ b/source/prog/serial_test.asm @@ -0,0 +1,58 @@ +include "charmap.inc" +include "video.inc" +include "hardware.inc" + +section "prog/serial_test.asm", rom0 + +prog_serial_test:: + call lcd_disable + call font_load + call pals_set_bw + call lcd_enable + + ld hl, string_title + bgcoord de, (screen_width - string_title.end + string_title + 1) / 2, 2 + call print + + call serial_init_master + +main_loop: + call joypad_update + bit joy_a_f, a + jr nz, .send_shit + + bgcoord hl, 7, 5 + call lcd_blank_wait + ld [hl], " " + +.continue + call vblank_wait + jr main_loop + +.send_shit + call vblank_wait + call joypad_update + bit joy_a_f, a + jr nz, .send_shit + + bgcoord hl, 7, 5 + call lcd_blank_wait + ld [hl], "A" + ld hl, transfer_buffer + ld de, NULL + ld bc, transfer_buffer.end - transfer_buffer + call serial_transfer + +.send_shit_wait + call vblank_wait + call serial_finished + jr nz, .send_shit_wait + + jr .continue + +transfer_buffer: +db $00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $AA, $BB, $CC, $DD, $EE, $FF +.end + +string_title: db "SERIAL TEST$" +.end diff --git a/source/video.inc b/source/video.inc index 89f7b37..9f1bd66 100644 --- a/source/video.inc +++ b/source/video.inc @@ -1,5 +1,3 @@ -; vim:set syn=asm: - if !def(_video_inc_) _video_inc_ equ 0