-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetmem.asm
77 lines (71 loc) · 2.15 KB
/
getmem.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
; these two are defined in m6502.c
global _bad_address
global _mem_base
global _cpu
psect text
; in C:
; uint8_t * get_mem( address ) uint16_t address;
; {
; uint8_t * base;
; base = mem_base[ address >> 12 ];
; if ( 0 == base )
; bad_address( address );
; return base + address;
; }
global _get_mem
_get_mem:
push ix ; save ix for the caller
ld ix, 4
add ix, sp ; the local variable is pointed to by ix
ld a, (ix + 1) ; use the top nibble to index into _mem_base
rrca
rrca
rrca ; shift just 3 times because array entries are 2 bytes long
and 30
ld l, a
ld h, 0
ld de, _mem_base
add hl, de ; hl now points to the array entry
ld e, (hl)
inc hl
ld d, (hl) ; de now has the array entry value
ld l, (ix) ; load the address argument
ld h, (ix + 1)
ld a, d ; is the array entry 0?
or e
jp nz, _good_address ; but only if it's valid
push hl
call _bad_address ; never going back
_good_address:
add hl, de ; add array entry to address argument
pop ix
ret
; in C:
; void xset_nz( x ) uint8_t x;
; {
; cpu.fNegative = !! ( x & 0x80 );
; cpu.fZero = !x;
; }
; using the macro in m6502 is faster than calling this function for HI-SOFT C
; global _set_nz
; _set_nz:
; push ix ; save ix for the caller
; ld ix, 4
; add ix, sp ; the local variable is pointed to by ix
; ld a, (ix) ; get x into register a
; cp 0
; jp nz, _nz_set_nz
; ld (_cpu + 7), a
; inc a
; jp _exit_set_nz
; _nz_set_nz:
; and 128
; jp z, _pos_set_nz
; inc a
; _pos_set_nz:
; ld (_cpu + 7), a
; xor a
; _exit_set_nz:
; ld (_cpu + 11), a
; pop ix
; ret