crlf to lf

This commit is contained in:
YamaArashi 2016-06-11 17:11:05 -07:00
parent d8dae96f35
commit cee4d559f9
2 changed files with 459 additions and 441 deletions

18
.gitattributes vendored Normal file
View File

@ -0,0 +1,18 @@
# Auto detect text files and perform LF normalization
* text eol=lf
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.asm text
# Denote all files that are truly binary and should not be modified.
*.png binary
*.2bpp binary
*.1bpp binary
*.rle binary
*.tilecoll binary
*.bst binary
*.map binary
*.wav binary
*.blk binary
*.pic binary

View File

@ -1,441 +1,441 @@
;\1 = event index ;\1 = event index
;\2 = return result in carry instead of zero flag ;\2 = return result in carry instead of zero flag
CheckEvent: MACRO CheckEvent: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld a, [wEventFlags + event_byte] ld a, [wEventFlags + event_byte]
IF _NARG > 1 IF _NARG > 1
IF ((\1) % 8) == 7 IF ((\1) % 8) == 7
add a add a
ELSE ELSE
REPT ((\1) % 8) + 1 REPT ((\1) % 8) + 1
rrca rrca
ENDR ENDR
ENDC ENDC
ELSE ELSE
bit (\1) % 8, a bit (\1) % 8, a
ENDC ENDC
ENDM ENDM
;\1 = event index ;\1 = event index
CheckEventReuseA: MACRO CheckEventReuseA: MACRO
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld a, [wEventFlags + event_byte] ld a, [wEventFlags + event_byte]
ENDC ENDC
bit (\1) % 8, a bit (\1) % 8, a
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index of the last event used before the branch ;\2 = event index of the last event used before the branch
CheckEventAfterBranchReuseA: MACRO CheckEventAfterBranchReuseA: MACRO
event_byte = ((\2) / 8) event_byte = ((\2) / 8)
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld a, [wEventFlags + event_byte] ld a, [wEventFlags + event_byte]
ENDC ENDC
bit (\1) % 8, a bit (\1) % 8, a
ENDM ENDM
;\1 = reg ;\1 = reg
;\2 = event index ;\2 = event index
;\3 = event index this event is relative to (optional, this is needed when there is a fixed flag address) ;\3 = event index this event is relative to (optional, this is needed when there is a fixed flag address)
EventFlagBit: MACRO EventFlagBit: MACRO
IF _NARG > 2 IF _NARG > 2
ld \1, ((\3) % 8) + ((\2) - (\3)) ld \1, ((\3) % 8) + ((\2) - (\3))
ELSE ELSE
ld \1, (\2) % 8 ld \1, (\2) % 8
ENDC ENDC
ENDM ENDM
;\1 = reg ;\1 = reg
;\2 = event index ;\2 = event index
EventFlagAddress: MACRO EventFlagAddress: MACRO
event_byte = ((\2) / 8) event_byte = ((\2) / 8)
ld \1, wEventFlags + event_byte ld \1, wEventFlags + event_byte
ENDM ENDM
;\1 = event index ;\1 = event index
CheckEventHL: MACRO CheckEventHL: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
CheckEventReuseHL: MACRO CheckEventReuseHL: MACRO
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
ENDM ENDM
; dangerous, only use when HL is guaranteed to be the desired value ; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index ;\1 = event index
CheckEventForceReuseHL: MACRO CheckEventForceReuseHL: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index of the last event used before the branch ;\2 = event index of the last event used before the branch
CheckEventAfterBranchReuseHL: MACRO CheckEventAfterBranchReuseHL: MACRO
event_byte = ((\2) / 8) event_byte = ((\2) / 8)
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
CheckAndSetEvent: MACRO CheckAndSetEvent: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
set (\1) % 8, [hl] set (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
CheckAndResetEvent: MACRO CheckAndResetEvent: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl] bit (\1) % 8, [hl]
res (\1) % 8, [hl] res (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
CheckAndSetEventA: MACRO CheckAndSetEventA: MACRO
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
bit (\1) % 8, a bit (\1) % 8, a
set (\1) % 8, a set (\1) % 8, a
ld [wEventFlags + ((\1) / 8)], a ld [wEventFlags + ((\1) / 8)], a
ENDM ENDM
;\1 = event index ;\1 = event index
CheckAndResetEventA: MACRO CheckAndResetEventA: MACRO
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
bit (\1) % 8, a bit (\1) % 8, a
res (\1) % 8, a res (\1) % 8, a
ld [wEventFlags + ((\1) / 8)], a ld [wEventFlags + ((\1) / 8)], a
ENDM ENDM
;\1 = event index ;\1 = event index
SetEvent: MACRO SetEvent: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
set (\1) % 8, [hl] set (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
SetEventReuseHL: MACRO SetEventReuseHL: MACRO
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
set (\1) % 8, [hl] set (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index of the last event used before the branch ;\2 = event index of the last event used before the branch
SetEventAfterBranchReuseHL: MACRO SetEventAfterBranchReuseHL: MACRO
event_byte = ((\2) / 8) event_byte = ((\2) / 8)
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
set (\1) % 8, [hl] set (\1) % 8, [hl]
ENDM ENDM
; dangerous, only use when HL is guaranteed to be the desired value ; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index ;\1 = event index
SetEventForceReuseHL: MACRO SetEventForceReuseHL: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
set (\1) % 8, [hl] set (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index ;\2 = event index
;\3, \4, ... = additional (optional) event indices ;\3, \4, ... = additional (optional) event indices
SetEvents: MACRO SetEvents: MACRO
SetEvent \1 SetEvent \1
rept (_NARG + -1) rept (_NARG + -1)
SetEventReuseHL \2 SetEventReuseHL \2
shift shift
endr endr
ENDM ENDM
;\1 = event index ;\1 = event index
ResetEvent: MACRO ResetEvent: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
res (\1) % 8, [hl] res (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
ResetEventReuseHL: MACRO ResetEventReuseHL: MACRO
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
res (\1) % 8, [hl] res (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index of the last event used before the branch ;\2 = event index of the last event used before the branch
ResetEventAfterBranchReuseHL: MACRO ResetEventAfterBranchReuseHL: MACRO
event_byte = ((\2) / 8) event_byte = ((\2) / 8)
IF event_byte != ((\1) / 8) IF event_byte != ((\1) / 8)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte ld hl, wEventFlags + event_byte
ENDC ENDC
res (\1) % 8, [hl] res (\1) % 8, [hl]
ENDM ENDM
; dangerous, only use when HL is guaranteed to be the desired value ; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index ;\1 = event index
ResetEventForceReuseHL: MACRO ResetEventForceReuseHL: MACRO
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
res (\1) % 8, [hl] res (\1) % 8, [hl]
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = event index ;\2 = event index
;\3 = event index (optional) ;\3 = event index (optional)
ResetEvents: MACRO ResetEvents: MACRO
ResetEvent \1 ResetEvent \1
rept (_NARG + -1) rept (_NARG + -1)
ResetEventReuseHL \2 ResetEventReuseHL \2
shift shift
endr endr
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = number of bytes away from the base address (optional, for matching the ROM) ;\2 = number of bytes away from the base address (optional, for matching the ROM)
dbEventFlagBit: MACRO dbEventFlagBit: MACRO
IF _NARG > 1 IF _NARG > 1
db ((\1) % 8) + ((\2) * 8) db ((\1) % 8) + ((\2) * 8)
ELSE ELSE
db ((\1) % 8) db ((\1) % 8)
ENDC ENDC
ENDM ENDM
;\1 = event index ;\1 = event index
;\2 = number of bytes away from the base address (optional, for matching the ROM) ;\2 = number of bytes away from the base address (optional, for matching the ROM)
dwEventFlagAddress: MACRO dwEventFlagAddress: MACRO
IF _NARG > 1 IF _NARG > 1
dw wEventFlags + ((\1) / 8) - (\2) dw wEventFlags + ((\1) / 8) - (\2)
ELSE ELSE
dw wEventFlags + ((\1) / 8) dw wEventFlags + ((\1) / 8)
ENDC ENDC
ENDM ENDM
;\1 = start ;\1 = start
;\2 = end ;\2 = end
SetEventRange: MACRO SetEventRange: MACRO
event_start_byte = ((\1) / 8) event_start_byte = ((\1) / 8)
event_end_byte = ((\2) / 8) event_end_byte = ((\2) / 8)
IF event_end_byte < event_start_byte IF event_end_byte < event_start_byte
FAIL "Incorrect argument order in SetEventRange." FAIL "Incorrect argument order in SetEventRange."
ENDC ENDC
IF event_start_byte == event_end_byte IF event_start_byte == event_end_byte
ld a, [wEventFlags + event_start_byte] ld a, [wEventFlags + event_start_byte]
or (1 << (((\2) % 8) + 1)) - (1 << ((\1) % 8)) or (1 << (((\2) % 8) + 1)) - (1 << ((\1) % 8))
ld [wEventFlags + event_start_byte], a ld [wEventFlags + event_start_byte], a
ELSE ELSE
event_fill_start = event_start_byte + 1 event_fill_start = event_start_byte + 1
event_fill_count = event_end_byte - event_start_byte - 1 event_fill_count = event_end_byte - event_start_byte - 1
IF ((\1) % 8) == 0 IF ((\1) % 8) == 0
event_fill_start = event_fill_start + -1 event_fill_start = event_fill_start + -1
event_fill_count = event_fill_count + 1 event_fill_count = event_fill_count + 1
ELSE ELSE
ld a, [wEventFlags + event_start_byte] ld a, [wEventFlags + event_start_byte]
or $ff - ((1 << ((\1) % 8)) - 1) or $ff - ((1 << ((\1) % 8)) - 1)
ld [wEventFlags + event_start_byte], a ld [wEventFlags + event_start_byte], a
ENDC ENDC
IF ((\2) % 8) == 7 IF ((\2) % 8) == 7
event_fill_count = event_fill_count + 1 event_fill_count = event_fill_count + 1
ENDC ENDC
IF event_fill_count == 1 IF event_fill_count == 1
ld hl, wEventFlags + event_fill_start ld hl, wEventFlags + event_fill_start
ld [hl], $ff ld [hl], $ff
ENDC ENDC
IF event_fill_count > 1 IF event_fill_count > 1
ld a, $ff ld a, $ff
ld hl, wEventFlags + event_fill_start ld hl, wEventFlags + event_fill_start
REPT event_fill_count + -1 REPT event_fill_count + -1
ld [hli], a ld [hli], a
ENDR ENDR
ld [hl], a ld [hl], a
ENDC ENDC
IF ((\2) % 8) == 0 IF ((\2) % 8) == 0
ld hl, wEventFlags + event_end_byte ld hl, wEventFlags + event_end_byte
set 0, [hl] set 0, [hl]
ELSE ELSE
IF ((\2) % 8) != 7 IF ((\2) % 8) != 7
ld a, [wEventFlags + event_end_byte] ld a, [wEventFlags + event_end_byte]
or (1 << (((\2) % 8) + 1)) - 1 or (1 << (((\2) % 8) + 1)) - 1
ld [wEventFlags + event_end_byte], a ld [wEventFlags + event_end_byte], a
ENDC ENDC
ENDC ENDC
ENDC ENDC
ENDM ENDM
;\1 = start ;\1 = start
;\2 = end ;\2 = end
;\3 = assume a is 0 if present ;\3 = assume a is 0 if present
ResetEventRange: MACRO ResetEventRange: MACRO
event_start_byte = ((\1) / 8) event_start_byte = ((\1) / 8)
event_end_byte = ((\2) / 8) event_end_byte = ((\2) / 8)
IF event_end_byte < event_start_byte IF event_end_byte < event_start_byte
FAIL "Incorrect argument order in ResetEventRange." FAIL "Incorrect argument order in ResetEventRange."
ENDC ENDC
IF event_start_byte == event_end_byte IF event_start_byte == event_end_byte
ld a, [wEventFlags + event_start_byte] ld a, [wEventFlags + event_start_byte]
and ~((1 << (((\2) % 8) + 1)) - (1 << ((\1) % 8))) & $ff and ~((1 << (((\2) % 8) + 1)) - (1 << ((\1) % 8))) & $ff
ld [wEventFlags + event_start_byte], a ld [wEventFlags + event_start_byte], a
ELSE ELSE
event_fill_start = event_start_byte + 1 event_fill_start = event_start_byte + 1
event_fill_count = event_end_byte - event_start_byte - 1 event_fill_count = event_end_byte - event_start_byte - 1
IF ((\1) % 8) == 0 IF ((\1) % 8) == 0
event_fill_start = event_fill_start + -1 event_fill_start = event_fill_start + -1
event_fill_count = event_fill_count + 1 event_fill_count = event_fill_count + 1
ELSE ELSE
ld a, [wEventFlags + event_start_byte] ld a, [wEventFlags + event_start_byte]
and ~($ff - ((1 << ((\1) % 8)) - 1)) & $ff and ~($ff - ((1 << ((\1) % 8)) - 1)) & $ff
ld [wEventFlags + event_start_byte], a ld [wEventFlags + event_start_byte], a
ENDC ENDC
IF ((\2) % 8) == 7 IF ((\2) % 8) == 7
event_fill_count = event_fill_count + 1 event_fill_count = event_fill_count + 1
ENDC ENDC
IF event_fill_count == 1 IF event_fill_count == 1
ld hl, wEventFlags + event_fill_start ld hl, wEventFlags + event_fill_start
ld [hl], 0 ld [hl], 0
ENDC ENDC
IF event_fill_count > 1 IF event_fill_count > 1
ld hl, wEventFlags + event_fill_start ld hl, wEventFlags + event_fill_start
; force xor a if we just to wrote to it above ; force xor a if we just to wrote to it above
IF (_NARG < 3) || (((\1) % 8) != 0) IF (_NARG < 3) || (((\1) % 8) != 0)
xor a xor a
ENDC ENDC
REPT event_fill_count + -1 REPT event_fill_count + -1
ld [hli], a ld [hli], a
ENDR ENDR
ld [hl], a ld [hl], a
ENDC ENDC
IF ((\2) % 8) == 0 IF ((\2) % 8) == 0
ld hl, wEventFlags + event_end_byte ld hl, wEventFlags + event_end_byte
res 0, [hl] res 0, [hl]
ELSE ELSE
IF ((\2) % 8) != 7 IF ((\2) % 8) != 7
ld a, [wEventFlags + event_end_byte] ld a, [wEventFlags + event_end_byte]
and ~((1 << (((\2) % 8) + 1)) - 1) & $ff and ~((1 << (((\2) % 8) + 1)) - 1) & $ff
ld [wEventFlags + event_end_byte], a ld [wEventFlags + event_end_byte], a
ENDC ENDC
ENDC ENDC
ENDC ENDC
ENDM ENDM
; returns whether both events are set in Z flag ; returns whether both events are set in Z flag
; This is counter-intuitive because the other event checks set the Z flag when ; This is counter-intuitive because the other event checks set the Z flag when
; the event is not set, but this sets the Z flag when the event is set. ; the event is not set, but this sets the Z flag when the event is set.
;\1 = event index 1 ;\1 = event index 1
;\2 = event index 2 ;\2 = event index 2
;\3 = try to reuse a (optional) ;\3 = try to reuse a (optional)
CheckBothEventsSet: MACRO CheckBothEventsSet: MACRO
IF ((\1) / 8) == ((\2) / 8) IF ((\1) / 8) == ((\2) / 8)
IF (_NARG < 3) || (((\1) / 8) != event_byte) IF (_NARG < 3) || (((\1) / 8) != event_byte)
event_byte = ((\1) / 8) event_byte = ((\1) / 8)
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
ENDC ENDC
and (1 << ((\1) % 8)) | (1 << ((\2) % 8)) and (1 << ((\1) % 8)) | (1 << ((\2) % 8))
cp (1 << ((\1) % 8)) | (1 << ((\2) % 8)) cp (1 << ((\1) % 8)) | (1 << ((\2) % 8))
ELSE ELSE
; This case doesn't happen in the original ROM. ; This case doesn't happen in the original ROM.
IF ((\1) % 8) == ((\2) % 8) IF ((\1) % 8) == ((\2) % 8)
push hl push hl
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
ld hl, wEventFlags + ((\2) / 8) ld hl, wEventFlags + ((\2) / 8)
and [hl] and [hl]
cpl cpl
bit ((\1) % 8), a bit ((\1) % 8), a
pop hl pop hl
ELSE ELSE
push bc push bc
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
and (1 << ((\1) % 8)) and (1 << ((\1) % 8))
ld b, a ld b, a
ld a, [wEventFlags + ((\2) / 8)] ld a, [wEventFlags + ((\2) / 8)]
and (1 << ((\2) % 8)) and (1 << ((\2) % 8))
or b or b
cp (1 << ((\1) % 8)) | (1 << ((\2) % 8)) cp (1 << ((\1) % 8)) | (1 << ((\2) % 8))
pop bc pop bc
ENDC ENDC
ENDC ENDC
ENDM ENDM
; returns the complement of whether either event is set in Z flag ; returns the complement of whether either event is set in Z flag
;\1 = event index 1 ;\1 = event index 1
;\2 = event index 2 ;\2 = event index 2
CheckEitherEventSet: MACRO CheckEitherEventSet: MACRO
IF ((\1) / 8) == ((\2) / 8) IF ((\1) / 8) == ((\2) / 8)
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
and (1 << ((\1) % 8)) | (1 << ((\2) % 8)) and (1 << ((\1) % 8)) | (1 << ((\2) % 8))
ELSE ELSE
; This case doesn't happen in the original ROM. ; This case doesn't happen in the original ROM.
IF ((\1) % 8) == ((\2) % 8) IF ((\1) % 8) == ((\2) % 8)
push hl push hl
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
ld hl, wEventFlags + ((\2) / 8) ld hl, wEventFlags + ((\2) / 8)
or [hl] or [hl]
bit ((\1) % 8), a bit ((\1) % 8), a
pop hl pop hl
ELSE ELSE
push bc push bc
ld a, [wEventFlags + ((\1) / 8)] ld a, [wEventFlags + ((\1) / 8)]
and (1 << ((\1) % 8)) and (1 << ((\1) % 8))
ld b, a ld b, a
ld a, [wEventFlags + ((\2) / 8)] ld a, [wEventFlags + ((\2) / 8)]
and (1 << ((\2) % 8)) and (1 << ((\2) % 8))
or b or b
pop bc pop bc
ENDC ENDC
ENDC ENDC
ENDM ENDM
; for handling fixed event bits when events are inserted/removed ; for handling fixed event bits when events are inserted/removed
;\1 = event index ;\1 = event index
;\2 = fixed flag bit ;\2 = fixed flag bit
AdjustEventBit: MACRO AdjustEventBit: MACRO
IF ((\1) % 8) != (\2) IF ((\1) % 8) != (\2)
add ((\1) % 8) - (\2) add ((\1) % 8) - (\2)
ENDC ENDC
ENDM ENDM