Skip to content

Commit

Permalink
SLOT+MMU: accept also exact start-address of slot instead of slot number
Browse files Browse the repository at this point in the history
  • Loading branch information
ped7g committed Jan 21, 2021
1 parent 6ee6856 commit b41f9ad
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 12 deletions.
18 changes: 16 additions & 2 deletions sjasm/directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ static void dirPAGE() {
}
}

static aint slotNumberFromPreciseAddress(aint inputValue) {
assert(Device);
if (inputValue < Device->SlotsCount) return inputValue; // seems to be slot number, not address
// check if the input value does exactly match start-address of some slot
int slotNum = Device->GetSlotOfA16(inputValue);
if (-1 == slotNum) return inputValue; // does not belong to any slot
if (inputValue != Device->GetSlot(slotNum)->Address) return inputValue; // not exact match
return slotNum; // return address converted into slot number
}

static void dirMMU() {
if (!DeviceID) {
Warning("MMU is allowed only in real device emulation mode (See DEVICE)");
Expand Down Expand Up @@ -417,10 +427,13 @@ static void dirMMU() {
check16(address);
address &= 0xFFFF;
}
// convert slot entered as addresses into slot numbering (must be precise start address of slot)
slot1 = slotNumberFromPreciseAddress(slot1);
slot2 = slotNumberFromPreciseAddress(slot2);
// validate argument values
if (slot1 < 0 || slot2 < slot1 || Device->SlotsCount <= slot2) {
char buf[LINEMAX];
SPRINTF1(buf, LINEMAX, "[MMU] Slot number(s) must be in range 0..%u and form a range",
SPRINTF1(buf, LINEMAX, "[MMU] Slot number(s) must be in range 0..%u (or exact starting address of slot) and form a range",
Device->SlotsCount - 1);
Error(buf, NULL, SUPPRESS);
return;
Expand Down Expand Up @@ -460,9 +473,10 @@ static void dirSLOT() {
Error("[SLOT] Syntax error in <slot_number>", lp, SUPPRESS);
return;
}
val = slotNumberFromPreciseAddress(val);
if (!Device->SetSlot(val)) {
char buf[LINEMAX];
SPRINTF1(buf, LINEMAX, "[SLOT] Slot number must be in range 0..%u", Device->SlotsCount - 1);
SPRINTF1(buf, LINEMAX, "[SLOT] Slot number must be in range 0..%u, or exact starting address of slot", Device->SlotsCount - 1);
Error(buf, NULL, IF_FIRST);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/devices/mmu.lst
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ mmu.asm(31): error: [MMU] Page number parsing failed: MMU 0 e,!
33 0000 ;; correct syntax, invalid arguments
mmu.asm(34): error: [MMU] Requested page(s) must be in range 0..7
34 0000 MMU 0,8
mmu.asm(35): error: [MMU] Slot number(s) must be in range 0..3 and form a range
mmu.asm(35): error: [MMU] Slot number(s) must be in range 0..3 (or exact starting address of slot) and form a range
35 0000 MMU 4,0
mmu.asm(36): error: [MMU] Slot number(s) must be in range 0..3 and form a range
mmu.asm(36): error: [MMU] Slot number(s) must be in range 0..3 (or exact starting address of slot) and form a range
36 0000 MMU 3 4,0
mmu.asm(37): error: [MMU] Requested page(s) must be in range 0..7
37 0000 MMU 0 0,8
mmu.asm(38): error: [MMU] Slot number(s) must be in range 0..3 and form a range
mmu.asm(38): error: [MMU] Slot number(s) must be in range 0..3 (or exact starting address of slot) and form a range
38 0000 MMU 1 0,0
mmu.asm(39): error: [MMU] Requested page(s) must be in range 0..7
39 0000 MMU 0 2,6 ; map pages 6, 7, 8 -> 8 is wrong
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/next_device.lst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
7 E002 ORG 0xE000
7 E000 33 33 DB "33"
8 E002 ; verify there are 8 slots and 224 pages
next_device.asm(9): error: [SLOT] Slot number must be in range 0..7
next_device.asm(9): error: [SLOT] Slot number must be in range 0..7, or exact starting address of slot
9 E002 SLOT 8 ; error
next_device.asm(10): error: [PAGE] Page number must be in range 0..223: 224
10 E002 PAGE 224 ; error
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/noslot64k_device.lst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
6 0002 ORG 0x0000
6 0000 33 33 DB "33"
7 0002 ; verify there is single slot and 32 pages
noslot64k_device.asm(8): error: [SLOT] Slot number must be in range 0..0
noslot64k_device.asm(8): error: [SLOT] Slot number must be in range 0..0, or exact starting address of slot
8 0002 SLOT 1 ; error
noslot64k_device.asm(9): error: [PAGE] Page number must be in range 0..31: 32
9 0002 PAGE 32 ; error
Expand Down
40 changes: 40 additions & 0 deletions tests/devices/slot_by_address.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DEVICE NONE ; set "none" explicitly, to avoid "global device" feature
SLOT $4000 ;; warning about non-device mode
MMU $4000, 1 ;; warning about non-device mode
DEVICE ZXSPECTRUM128

; mark banks content with values for checking results
MMU 0, 0, 0 : DW '00'
MMU 0, 1, 0 : DW '11'
MMU 0, 2, 0 : DW '22'
MMU 0, 3, 0 : DW '33'
MMU 0, 4, 0 : DW '44'
MMU 0, 5, 0 : DW '55'
MMU 0, 6, 0 : DW '66'
MMU 0, 7, 0 : DW '77'
; remap ZX128 to banks 0:1:2:3
MMU 0 3, 0
ASSERT '00' == {$0000} && '11' == {$4000} && '22' == {$8000} && '33' == {$C000}

; test SLOT with valid values
SLOT $0000 : PAGE 4
SLOT $4000 : PAGE 5
SLOT $8000 : PAGE 6
SLOT $C000 : PAGE 7
ASSERT '44' == {$0000} && '55' == {$4000} && '66' == {$8000} && '77' == {$C000}

; test MMU with valid values
MMU $0000 w, 1
MMU $4000 w, 2
MMU $8000 w, 3
MMU $C000 w, 4
ASSERT '11' == {$0000} && '22' == {$4000} && '33' == {$8000} && '44' == {$C000}

MMU $0000 $C000, 2
ASSERT '22' == {$0000} && '33' == {$4000} && '44' == {$8000} && '55' == {$C000}

; test with invalid value (address of start of slot must be exact)
SLOT $1000
SLOT 4
MMU $1000, 0
MMU 4, 0
64 changes: 64 additions & 0 deletions tests/devices/slot_by_address.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# file opened: slot_by_address.asm
1 0000 DEVICE NONE ; set "none" explicitly, to avoid "global device" feature
slot_by_address.asm(2): warning: SLOT only allowed in real device emulation mode (See DEVICE)
2 0000 SLOT $4000 ;; warning about non-device mode
slot_by_address.asm(3): warning: MMU is allowed only in real device emulation mode (See DEVICE)
3 0000 MMU $4000, 1 ;; warning about non-device mode
4 0000 DEVICE ZXSPECTRUM128
5 0000
6 0000 ; mark banks content with values for checking results
7 0000 MMU 0, 0, 0
7 0000 30 30 DW '00'
8 0002 MMU 0, 1, 0
8 0000 31 31 DW '11'
9 0002 MMU 0, 2, 0
9 0000 32 32 DW '22'
10 0002 MMU 0, 3, 0
10 0000 33 33 DW '33'
11 0002 MMU 0, 4, 0
11 0000 34 34 DW '44'
12 0002 MMU 0, 5, 0
12 0000 35 35 DW '55'
13 0002 MMU 0, 6, 0
13 0000 36 36 DW '66'
14 0002 MMU 0, 7, 0
14 0000 37 37 DW '77'
15 0002 ; remap ZX128 to banks 0:1:2:3
16 0002 MMU 0 3, 0
17 0002 ASSERT '00' == {$0000} && '11' == {$4000} && '22' == {$8000} && '33' == {$C000}
18 0002
19 0002 ; test SLOT with valid values
20 0002 SLOT $0000
20 0002 PAGE 4
21 0002 SLOT $4000
21 0002 PAGE 5
22 0002 SLOT $8000
22 0002 PAGE 6
23 0002 SLOT $C000
23 0002 PAGE 7
24 0002 ASSERT '44' == {$0000} && '55' == {$4000} && '66' == {$8000} && '77' == {$C000}
25 0002
26 0002 ; test MMU with valid values
27 0002 MMU $0000 w, 1
28 0002 MMU $4000 w, 2
29 0002 MMU $8000 w, 3
30 0002 MMU $C000 w, 4
31 0002 ASSERT '11' == {$0000} && '22' == {$4000} && '33' == {$8000} && '44' == {$C000}
32 0002
33 0002 MMU $0000 $C000, 2
34 0002 ASSERT '22' == {$0000} && '33' == {$4000} && '44' == {$8000} && '55' == {$C000}
35 0002
36 0002 ; test with invalid value (address of start of slot must be exact)
slot_by_address.asm(37): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
37 0002 SLOT $1000
slot_by_address.asm(38): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
38 0002 SLOT 4
slot_by_address.asm(39): error: [MMU] Slot number(s) must be in range 0..3 (or exact starting address of slot) and form a range
39 0002 MMU $1000, 0
slot_by_address.asm(40): error: [MMU] Slot number(s) must be in range 0..3 (or exact starting address of slot) and form a range
40 0002 MMU 4, 0
41 0002
# file closed: slot_by_address.asm

Value Label
------ - -----------------------------------------------------------
6 changes: 3 additions & 3 deletions tests/devices/zx256_to_zx1M.lst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ zx256_to_zx1M.asm(11): error: [PAGE] Page number must be in range 0..15: 16
17 0002 PAGE 15
17 0002 ASSERT {0xC000} == "??"
18 0002
zx256_to_zx1M.asm(19): error: [SLOT] Slot number must be in range 0..3
zx256_to_zx1M.asm(19): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
19 0002 SLOT 4 ; error
20 0002
21 0002 ; pages: 7:15:7:15
Expand Down Expand Up @@ -323,7 +323,7 @@ zx256_to_zx1M.asm(44): error: [PAGE] Page number must be in range 0..31: 32
50 0002 PAGE 31
50 0002 ASSERT {0xC000} == "OO"
51 0002
zx256_to_zx1M.asm(52): error: [SLOT] Slot number must be in range 0..3
zx256_to_zx1M.asm(52): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
52 0002 SLOT 4 ; error
53 0002
54 0002 ; pages: 7:31:7:31
Expand Down Expand Up @@ -694,7 +694,7 @@ zx256_to_zx1M.asm(77): error: [PAGE] Page number must be in range 0..63: 64
83 0002 PAGE 63
83 0002 ASSERT {0xC000} == $6F6F
84 0002
zx256_to_zx1M.asm(85): error: [SLOT] Slot number must be in range 0..3
zx256_to_zx1M.asm(85): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
85 0002 SLOT 4 ; error
86 0002
87 0002 ; pages: 7:63:7:63
Expand Down
4 changes: 2 additions & 2 deletions tests/devices/zx48_and_128.lst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ zx48_and_128.asm(9): error: [PAGE] Page number must be in range 0..3: 4
14 0002 PAGE 1
14 0002 ASSERT {0xC000} == "11"
15 0002
zx48_and_128.asm(16): error: [SLOT] Slot number must be in range 0..3
zx48_and_128.asm(16): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
16 0002 SLOT 4 ; error
17 0002
18 0002 ; pages: 3:1:3:1
Expand Down Expand Up @@ -106,7 +106,7 @@ zx48_and_128.asm(41): error: [PAGE] Page number must be in range 0..7: 8
46 0002 PAGE 5
46 0002 ASSERT {0xC000} == "55"
47 0002
zx48_and_128.asm(48): error: [SLOT] Slot number must be in range 0..3
zx48_and_128.asm(48): error: [SLOT] Slot number must be in range 0..3, or exact starting address of slot
48 0002 SLOT 4 ; error
49 0002
50 0002 ; pages: 7:5:7:5
Expand Down

0 comments on commit b41f9ad

Please sign in to comment.