Browse Source

Reorganize things a little so I can write small programs

master
mid-kid 4 years ago
parent
commit
b942730a12
  1. 2
      source/charmap.inc
  2. 4
      source/hardware.inc
  3. 18
      source/home/start.asm
  4. 36
      source/home/text.asm
  5. 43
      source/home/video.asm
  6. 121
      source/main.asm
  7. 58
      source/prog/serial_test.asm
  8. 2
      source/video.inc

2
source/charmap.inc

@ -1,5 +1,3 @@
; vim:set syn=asm:
if 0 ;!def(_charmap_inc_) if 0 ;!def(_charmap_inc_)
_charmap_inc_ equ 0 _charmap_inc_ equ 0

4
source/hardware.inc

@ -89,6 +89,10 @@ r_stat_mode_vram equ 3 << r_stat_mode_f
r_ly equ $ff44 r_ly equ $ff44
r_ly_vblank equ 144 r_ly_vblank equ 144
r_bgp equ $ff47
r_obp0 equ $ff48
r_obp1 equ $ff49
rsreset rsreset
r_bcps equ $ff68 r_bcps equ $ff68
bits r_bcps_offs, 3 bits r_bcps_offs, 3

18
source/home/start.asm

@ -2,7 +2,7 @@ include "hardware.inc"
include "defines.inc" include "defines.inc"
NULL equ 0 NULL equ 0
global NULL export NULL
section "home/start.asm@wram0", wram0 section "home/start.asm@wram0", wram0
ds $100 - 1 ds $100 - 1
@ -36,7 +36,7 @@ _start:
.console_cgb .console_cgb
dec b dec b
jr z, .console_agb jr z, .console_end
dec c ; console_cgb dec c ; console_cgb
.console_end .console_end
@ -55,23 +55,22 @@ if def(ENABLE_CLEAR)
endc endc
ld sp, w_stack ld sp, w_stack
ldh a, [h_console]
push af
if def(ENABLE_CLEAR) if def(ENABLE_CLEAR)
; Clear the hram and wram1 ; Clear the hram and wram1
ldh a, [h_console]
push af
xor a xor a
ld hl, mmap_hram ld hl, mmap_hram
ld bc, mmap_hram_end - mmap_hram ld bc, mmap_hram_end - mmap_hram
call memset call memset
pop af
ldh [h_console], a
ld hl, mmap_wramx ld hl, mmap_wramx
ld bc, mmap_wramx_end - mmap_wramx ld bc, mmap_wramx_end - mmap_wramx
call memset call memset
endc endc
pop af
ldh [h_console], a
if def(ENABLE_CGB) && def(ENABLE_CLEAR) if def(ENABLE_CGB) && def(ENABLE_CLEAR)
; Clear the different wram banks ; Clear the different wram banks
cp console_cgb cp console_cgb
@ -93,6 +92,11 @@ if def(ENABLE_CGB) && def(ENABLE_CLEAR)
.end .end
endc endc
call audio_disable
if def(ENABLE_CLEAR)
call vram_clear
endc
ei ei
jp main jp main

36
source/home/text.asm

@ -1,4 +1,21 @@
include "charmap.inc" 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 section "home/text.asm", rom0
@ -40,3 +57,22 @@ print_num_3digit::
dec l dec l
jr nz, .loop jr nz, .loop
ret 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

43
source/home/video.asm

@ -52,3 +52,46 @@ vram_clear::
ld hl, mmap_oam ld hl, mmap_oam
ld bc, mmap_oam_end - mmap_oam ld bc, mmap_oam_end - mmap_oam
jp memset 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

121
source/main.asm

@ -1,127 +1,22 @@
include "charmap.inc" include "charmap.inc"
include "defines.inc" include "defines.inc"
include "video.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 section "main.asm", rom0
main:: main::
call audio_disable
call lcd_disable call lcd_disable
if def(ENABLE_CLEAR) call font_load
call vram_clear call pals_set_bw
endc ;call vram_clear_bgmap
; 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 lcd_enable call lcd_enable
ld hl, string_something ld hl, string_something
bgcoord de, 5, 2 bgcoord de, (screen_width - string_something.end + string_something + 1) / 2, 2
call print call print
call serial_init_master ;call prog_serial_test
jp _halt_
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_something: db "SOMETHING$" string_something: db "SOMETHING$"
.end

58
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

2
source/video.inc

@ -1,5 +1,3 @@
; vim:set syn=asm:
if !def(_video_inc_) if !def(_video_inc_)
_video_inc_ equ 0 _video_inc_ equ 0

Loading…
Cancel
Save