Skip to content

Commit

Permalink
Define and use a couple of macros for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Apr 26, 2021
1 parent 2cb7fe6 commit 0ccd899
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions game.z80
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ BDOS_READ_INPUT: EQU 0x0A
BDOS_OUTPUT_SINGLE_CHARACTER: EQU 0x02


;
; Simple macro to inject "L" into our input buffer,
; and call the LOOK handler.
;
MACRO FAKE_LOOK
ld hl, input_buffer+2
ld a, 'L'
ld (hl), a
call look_function
ENDM


;
; Simple macro to push all registers
;
MACRO PUSH_ALL
push af
push bc
push de
push hl
ENDM

;
; Simple macro to pop all registers
;
MACRO POP_ALL
pop hl
pop de
pop bc
pop af
ENDM



ORG 100h

;
Expand Down Expand Up @@ -98,10 +132,7 @@ ENDIF

; Show the starting-location.
call show_newline
ld hl, input_buffer+2
ld a, 'L'
ld (hl), a
call look_function
FAKE_LOOK

; The start of our game loop.
;
Expand Down Expand Up @@ -659,33 +690,22 @@ Num2: inc a
add hl,bc
jr c,Num2
sbc hl,bc
push hl
push de
push bc
push af

PUSH_ALL

ld c, BDOS_OUTPUT_SINGLE_CHARACTER
ld e, a
call BDOS_ENTRY_POINT

pop af
pop bc
pop de
pop hl
POP_ALL
ret

show_a_register:
push hl
push de
push bc
push af
PUSH_ALL
ld h,0
ld l,a
call DispHL
pop af
pop bc
pop de
pop hl
POP_ALL
ret


Expand Down Expand Up @@ -825,12 +845,12 @@ down_found_trap:
cp 255
jr nz,dark_destination

ld hl,CURRENT_LOCATION
ld hl, CURRENT_LOCATION
ld (hl),3
call look_function
ret
dark_destination:
ld hl,CURRENT_LOCATION
ld hl, CURRENT_LOCATION
ld (hl),4
call look_function
ret
Expand Down Expand Up @@ -974,7 +994,7 @@ examine_found_it:
; If we're in the middle-floor we can use the telephone
;
call_function:
ld hl,CURRENT_LOCATION
ld hl, CURRENT_LOCATION
ld a,(hl)
cp 1
jr z, call_proceed
Expand Down Expand Up @@ -1256,17 +1276,11 @@ inventory_test_item:
ld a,(hl)
cp 0xff ; 0xff means the item is being carried
jr nz, inv_item_not_carried
push hl
push de
push bc
push af
PUSH_ALL
call show_tab
call show_msg
call show_newline
pop af
pop bc
pop de
pop hl
POP_ALL
inv_item_not_carried:
inc hl
djnz inventory_test_item
Expand Down Expand Up @@ -1387,17 +1401,11 @@ look_item_loop:
or e
jr z, item_not_present

push hl
push de
push bc
push af
PUSH_ALL
call show_tab
call show_msg
call show_newline
pop af
pop bc
pop de
pop hl
POP_ALL
item_not_present:
inc hl
djnz look_item_loop
Expand Down Expand Up @@ -1644,7 +1652,7 @@ drop_mirror_fn:

; Set the location to be the current location
push hl
ld hl,CURRENT_LOCATION
ld hl, CURRENT_LOCATION
ld a,(hl)
pop hl
ld (hl), a
Expand Down Expand Up @@ -1753,10 +1761,7 @@ use_torch_found_t2:
call show_msg

; show the location
ld hl, input_buffer+2
ld a, 'L'
ld (hl), a
call look_function
FAKE_LOOK

out_of_here:
ret
Expand Down

0 comments on commit 0ccd899

Please sign in to comment.