2019-04-21 23:25:52 +10:00
|
|
|
; *** Requirements ***
|
|
|
|
; JUMP_UPCASE
|
|
|
|
|
2019-05-01 11:13:37 +10:00
|
|
|
; *** Consts ***
|
|
|
|
TOK_INSTR .equ 0x01
|
2019-05-01 11:27:44 +10:00
|
|
|
TOK_DIRECTIVE .equ 0x02
|
2019-05-01 11:13:37 +10:00
|
|
|
TOK_BAD .equ 0xff
|
|
|
|
|
2019-04-21 23:25:52 +10:00
|
|
|
; *** Code ***
|
2019-05-01 12:27:11 +10:00
|
|
|
; Parse line in (HL) and read the next token in BC. The token is written on
|
|
|
|
; two bytes (B and C). B is a token type (TOK_* constants) and C is an ID
|
|
|
|
; specific to that token type.
|
|
|
|
; Advance HL to after the read word.
|
|
|
|
; If no token matches, TOK_BAD is written to B
|
2019-04-21 23:25:52 +10:00
|
|
|
tokenize:
|
2019-05-01 06:08:21 +10:00
|
|
|
call toWord
|
2019-04-21 23:25:52 +10:00
|
|
|
call readWord
|
2019-05-01 12:27:11 +10:00
|
|
|
push hl ; Save advanced HL for later
|
|
|
|
ld hl, scratchpad
|
2019-05-01 10:25:38 +10:00
|
|
|
call getInstID
|
2019-05-01 11:27:44 +10:00
|
|
|
jr z, .instr
|
|
|
|
call getDirectiveID
|
|
|
|
jr z, .direc
|
2019-05-01 11:13:37 +10:00
|
|
|
; no match
|
2019-05-01 12:27:11 +10:00
|
|
|
ld b, TOK_BAD
|
|
|
|
jr .end
|
2019-05-01 11:27:44 +10:00
|
|
|
.instr:
|
2019-05-01 12:27:11 +10:00
|
|
|
ld b, TOK_INSTR
|
2019-05-01 11:27:44 +10:00
|
|
|
jr .end
|
|
|
|
.direc:
|
2019-05-01 12:27:11 +10:00
|
|
|
ld b, TOK_DIRECTIVE
|
2019-05-01 11:27:44 +10:00
|
|
|
.end:
|
2019-05-01 12:27:11 +10:00
|
|
|
ld c, a
|
|
|
|
pop hl
|
2019-05-01 07:04:42 +10:00
|
|
|
ret
|