summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-10-06 08:02:23 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-10-06 08:02:23 -0400
commit8aa8586b03568d3a3d6eba39269a1b79510bc835 (patch)
treeb674ea424fd816fe4219b4423c2e3544b1ff58ce
parent8c880c339000010260a927c3a0f28f9049b8a0b8 (diff)
- Made the stack pointer 64 bit, rather than 16 bit.
This is to allow for making the stack bigger for anything that needs to change the size of it. - Made the SuB Suite set the stack pointer to the end of the usable RAM, and allow for changing the stack size. In this case, the size of the stack is currently set to 192K, with the end of the heap being just below the stack.
-rw-r--r--disasm.c2
-rw-r--r--opcode.h3
-rw-r--r--programs/sub-suite/declare.s3
-rw-r--r--programs/sub-suite/subeditor.s12
-rw-r--r--sux.c24
-rw-r--r--sux.h21
-rw-r--r--test/add-sub.s6
-rw-r--r--test/getramsize.s2
-rw-r--r--test/hello-world.s3
-rw-r--r--test/load-store.s2
-rw-r--r--test/popcnt.s2
-rw-r--r--test/popcnt2.s2
-rw-r--r--test/rotate.s2
-rw-r--r--test/stack-frame.s3
-rw-r--r--test/subroutine.s2
-rw-r--r--test/test-stack.s3
16 files changed, 42 insertions, 50 deletions
diff --git a/disasm.c b/disasm.c
index da468dd..3465f38 100644
--- a/disasm.c
+++ b/disasm.c
@@ -14,7 +14,7 @@ void print_regs(struct sux *cpu, uint8_t lines, uint8_t thread) {
wprintw(scr, ", b: $%016"PRIX64, cpu->b);
wprintw(scr, ", x: $%016"PRIX64, cpu->x);
wprintw(scr, ", y: $%016"PRIX64, cpu->y);
- wprintw(scr, ", sp: $%04X", cpu->sp);
+ wprintw(scr, ", sp: $%"PRIX64, cpu->sp);
wprintw(scr, ", ps: $%02X", cpu->ps.u8[thread]);
wprintw(scr, ", inst: ");
}
diff --git a/opcode.h b/opcode.h
index cd883d4..1c11ca5 100644
--- a/opcode.h
+++ b/opcode.h
@@ -56,8 +56,7 @@ struct sux {
union reg ps; /* The processor status register. */
uint64_t a, b, y, x; /* Registers A, B, X, and Y. */
uint64_t pc; /* Program counter. */
- uint16_t sp; /* Stack pointer. */
- uint16_t stk_st; /* Starting address of each threads stack. */
+ uint64_t sp; /* Stack pointer. */
uint64_t clk; /* Number of clock cycles. */
uint8_t crt; /* Current running threads. */
};
diff --git a/programs/sub-suite/declare.s b/programs/sub-suite/declare.s
index 6a8c90f..7b419e2 100644
--- a/programs/sub-suite/declare.s
+++ b/programs/sub-suite/declare.s
@@ -102,6 +102,9 @@ LWSIZE = $1000 ; Linewrap table size, in bytes.
; Magic number used by findramend.
MAGIC = $AA
+; Size of the Stack.
+STKSIZE = $30000
+
; Heap related values.
HEAPORG = $30000 ; Starting point of the heap.
diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s
index d98d068..addd64a 100644
--- a/programs/sub-suite/subeditor.s
+++ b/programs/sub-suite/subeditor.s
@@ -6,11 +6,19 @@
.org $8000
reset:
cps ; Reset the processor status register.
- ldx.w #$FFFF ; Reset the stack pointer.
+ ldx.d #$2FFFF ; Reset the stack pointer.
txs ;
ldy #0 ; Reset Y.
tyx ; Reset X.
jsr init_heap ; Initialize the heap.
+ inc step ;
+ tax ; Set the stack pointer to the end of RAM.
+ txs ;
+ sec ; Prepare for a non borrowing subtract.
+ sbc.d #STKSIZE ; Subtract the stack size, from the end of RAM.
+ sta.q heapend ; Save the end of the heap.
+ and #0 ; Reset A.
+ tax ; Reset X.
jsr init_tables ; Initialize the main tables.
; jsr test_free ;
jsr clr_scr ; Clear the screen.
@@ -27,8 +35,6 @@ init_heap:
jsr findramend ; Find the end of the heap.
plb.q ; Restore the value in B.
plx.q ; Restore the value in X.
- sta.q heapend ; Save the end of the heap.
- and #0 ; Reset A.
rts ; End of init_heap.
diff --git a/sux.c b/sux.c
index acd834e..adca16f 100644
--- a/sux.c
+++ b/sux.c
@@ -228,7 +228,6 @@ void *run(void *args) {
uint8_t rs = (prefix >> 4) & 3;
uint8_t size = (/***/1 << rs) - 1;
uint8_t check_io = (am != IMM);
- uint64_t sp = (cpu->sp & 0xFFFF) | (cpu->stk_st << 16);
#if debug && !bench
#if keypoll
pthread_mutex_lock(&mutex);
@@ -265,16 +264,16 @@ void *run(void *args) {
case PHB_IMP: push(cpu, cpu->b , size, thread); break; /* PusH B register to stack. */
case PHY_IMP: push(cpu, cpu->y , size, thread); break; /* PusH Y register to stack. */
case PHX_IMP: push(cpu, cpu->x , size, thread); break; /* PusH X register to stack. */
- case TAY_IMP: cpu->y = transfer(cpu, cpu->a, value.u64, opcode, prefix, thread); break; /* Transfer Accumulator to Y. */
- case TAX_IMP: cpu->x = transfer(cpu, cpu->a, value.u64, opcode, prefix, thread); break; /* Transfer Accumulator to Y. */
- case TYX_IMP: cpu->x = transfer(cpu, cpu->y, value.u64, opcode, prefix, thread); break; /* Transfer Y to X. */
- case TYA_IMP: cpu->a = transfer(cpu, cpu->y, value.u64, opcode, prefix, thread); break; /* Transfer Y to Accumulator. */
- case TXA_IMP: cpu->a = transfer(cpu, cpu->x, value.u64, opcode, prefix, thread); break; /* Transfer X to Accumulator. */
- case TXY_IMP: cpu->y = transfer(cpu, cpu->x, value.u64, opcode, prefix, thread); break; /* Transfer X to Y. */
- case TAB_IMP: cpu->b = transfer(cpu, cpu->a, value.u64, opcode, prefix, thread); break; /* Transfer Accumulator to B. */
- case TSX_IMP: cpu->x = transfer(cpu, sp, value.u64, opcode, prefix, thread); break; /* Transfer Stack pointer to X. */
- case TBA_IMP: cpu->a = transfer(cpu, cpu->b, value.u64, opcode, prefix, thread); break; /* Transfer B to Accumulator. */
- case TXS_IMM: cpu->sp = transfer(cpu, cpu->x, value.u64, opcode, prefix, thread); break; /* Transfer X to Stack pointer. */
+ case TAY_IMP: cpu->y = transfer(cpu, cpu->a , value.u64, thread); break; /* Transfer Accumulator to Y. */
+ case TAX_IMP: cpu->x = transfer(cpu, cpu->a , value.u64, thread); break; /* Transfer Accumulator to Y. */
+ case TYX_IMP: cpu->x = transfer(cpu, cpu->y , value.u64, thread); break; /* Transfer Y to X. */
+ case TYA_IMP: cpu->a = transfer(cpu, cpu->y , value.u64, thread); break; /* Transfer Y to Accumulator. */
+ case TXA_IMP: cpu->a = transfer(cpu, cpu->x , value.u64, thread); break; /* Transfer X to Accumulator. */
+ case TXY_IMP: cpu->y = transfer(cpu, cpu->x , value.u64, thread); break; /* Transfer X to Y. */
+ case TAB_IMP: cpu->b = transfer(cpu, cpu->a , value.u64, thread); break; /* Transfer Accumulator to B. */
+ case TSX_IMP: cpu->x = transfer(cpu, cpu->sp, value.u64, thread); break; /* Transfer Stack pointer to X. */
+ case TBA_IMP: cpu->a = transfer(cpu, cpu->b , value.u64, thread); break; /* Transfer B to Accumulator. */
+ case TXS_IMM: cpu->sp = transfer(cpu, cpu->x , value.u64, thread); break; /* Transfer X to Stack pointer. */
case BRA_REL: /* BRA Relative. */
case JMP_AB: /* JMP Absolute. */
case JMP_Z: /* JMP Zero Matrix. */
@@ -656,8 +655,7 @@ int main(int argc, char **argv) {
uint16_t vec = 0xFFC0;
uint8_t offset;
for (int i = 0; i < THREADS; i++) {
- thr[i].sx.sp = 0xFFFF;
- thr[i].sx.stk_st = i+1;
+ thr[i].sx.sp = (i << 16) | 0xFFFF;
offset = (i) ? ((i-1) << 3) : 0;
vec = (i) ? 0xFF50 : 0xFFC0;
thr[i].sx.a = 0;
diff --git a/sux.h b/sux.h
index 744a2cc..5bfdb44 100644
--- a/sux.h
+++ b/sux.h
@@ -141,8 +141,8 @@ static inline void write_value(struct sux *cpu, uint64_t value, uint64_t address
static inline uint64_t offset_addr(struct sux *cpu, uint64_t offset, uint8_t size, uint8_t inc_clk, uint8_t prefix) {
uint64_t of;
switch (prefix >> 6) {
- case 1: of = ((cpu->stk_st << 16) | cpu->sp); break;
- case 2: of = cpu->pc ; break;
+ case 1: of = cpu->sp; break;
+ case 2: of = cpu->pc; break;
}
#if getclk
cpu->clk += inc_clk;
@@ -278,30 +278,19 @@ static inline uint64_t adc(struct sux *cpu, uint64_t reg, uint64_t value, uint8_
return sum;
}
-static inline uint64_t transfer(struct sux *cpu, uint64_t src, uint64_t value, uint8_t opcode, uint8_t prefix, uint8_t thread) {
- switch (opcode) {
- case TXS_IMM:
- if (prefix == 0x13 && (value == thread+1 || value > 8)) {
- cpu->stk_st = value & 0xFF;
- cpu->stk_st += value << 16;
- cpu->pc+=2;
- }
- default: break;
- }
+static inline uint64_t transfer(struct sux *cpu, uint64_t src, uint64_t value, uint8_t thread) {
setflag(src == 0, Z);
setflag(src >> 63, N);
return src;
}
static inline void push(struct sux *cpu, uint64_t value, uint8_t size, uint8_t thread) {
- uint64_t sbr = (cpu->stk_st << 16);
- write_value(cpu, value, (sbr+cpu->sp)-size, size, 1, 0);
+ write_value(cpu, value, cpu->sp-size, size, 1, 0);
cpu->sp -= size+1;
}
static inline uint64_t pull(struct sux *cpu, uint8_t size, uint8_t thread) {
- uint64_t sbr = (cpu->stk_st << 16);
- uint64_t value = read_value(cpu, 0, sbr+cpu->sp+1, size, 1, 0);
+ uint64_t value = read_value(cpu, 0, cpu->sp+1, size, 1, 0);
cpu->sp += size+1;
return value;
}
diff --git a/test/add-sub.s b/test/add-sub.s
index 3dfdca4..d923cdc 100644
--- a/test/add-sub.s
+++ b/test/add-sub.s
@@ -6,7 +6,7 @@
.org 0
reset:
cps ; Clear the processor status register.
- ldx.w #$FFFF ; Reset the stack pointer.
+ ldx.d #$2FFFF ; Reset the stack pointer.
txs ;
and #0 ; Reset A.
tab ; Reset B.
@@ -15,11 +15,11 @@ up:
inc ; Increment the counter.
cmp #$FF ; Did the accumulator overflow?
bcs down ; Yes, so start decrementing.
- jmp up ; No, so keep incrementing.
+ bra up ; No, so keep incrementing.
down:
dec ; Did the accumulator underflow?
beq up ; Yes, so start incrementing.
- jmp down ; No, so keep decrementing.
+ bra down ; No, so keep decrementing.
.org $FFC0
.qword reset
diff --git a/test/getramsize.s b/test/getramsize.s
index cd2c69b..3cf9e38 100644
--- a/test/getramsize.s
+++ b/test/getramsize.s
@@ -12,7 +12,7 @@ ptr1:
.org $8000
reset:
cps ; Boilerplate reset code.
- ldx.w #$FFFF ;
+ ldx.d #$2FFFF ;
txs ;
and #0 ; Reset A.
tax ;
diff --git a/test/hello-world.s b/test/hello-world.s
index f3b540a..cf2d2a8 100644
--- a/test/hello-world.s
+++ b/test/hello-world.s
@@ -19,7 +19,7 @@ buffer:
.org $8000
reset:
cps ; Reset the processor status.
- ldx.w #$FFFF ; Set up the stack pointer.
+ ldx.d #$2FFFF ; Set up the stack pointer.
txs ; Reset the stack pointer.
; Start of main program.
@@ -65,4 +65,3 @@ spin:
.qword spin
a
d
-
diff --git a/test/load-store.s b/test/load-store.s
index 60a5a8f..abb7e74 100644
--- a/test/load-store.s
+++ b/test/load-store.s
@@ -2,7 +2,7 @@
reset:
cps
- ldx.w #$FFFF
+ ldx.d #$2FFFF
txs
@clear:
and #0
diff --git a/test/popcnt.s b/test/popcnt.s
index 7682653..cdb71c5 100644
--- a/test/popcnt.s
+++ b/test/popcnt.s
@@ -22,7 +22,7 @@ popcnt:
reset:
cps ; Boilerplate reset code.
- ldx.w #$FFFF ;
+ ldx.d #$2FFFF ;
txs ;
and #0 ; Reset A.
tab ; Reset B.
diff --git a/test/popcnt2.s b/test/popcnt2.s
index 503b074..5739fb7 100644
--- a/test/popcnt2.s
+++ b/test/popcnt2.s
@@ -19,7 +19,7 @@ popcnt:
reset:
cps ; Boilerplate reset code.
- ldx.w #$FFFF ;
+ ldx.d #$2FFFF ;
txs ;
and #0 ; Reset A.
tab ; Reset B.
diff --git a/test/rotate.s b/test/rotate.s
index 6115e94..90f16ba 100644
--- a/test/rotate.s
+++ b/test/rotate.s
@@ -9,7 +9,7 @@ tmp:
.org $8000
reset:
cps ;
- ldx.w #$FFFF ;
+ ldx.d #$2FFFF ;
txs ;
and #0 ;
tax ;
diff --git a/test/stack-frame.s b/test/stack-frame.s
index 0f631b9..fefb3d0 100644
--- a/test/stack-frame.s
+++ b/test/stack-frame.s
@@ -8,7 +8,7 @@ var:
.org $8000
reset:
cps ;
- ldx.w #$FFFF ;
+ ldx.d #$2FFFF ;
txs ;
lda #0 ;
tay ;
@@ -35,4 +35,3 @@ a
;v
;q
d
-
diff --git a/test/subroutine.s b/test/subroutine.s
index b7d8d17..e06ac48 100644
--- a/test/subroutine.s
+++ b/test/subroutine.s
@@ -13,7 +13,7 @@ buf:
.org $8000
reset:
cps ; Reset the processor status register.
- ldx.w #$FFFF ; Reset the stack pointer.
+ ldx.d #$2FFFF ; Reset the stack pointer.
txs ;
@bench:
tay ; Reset Y.
diff --git a/test/test-stack.s b/test/test-stack.s
index a63f54a..c3160d3 100644
--- a/test/test-stack.s
+++ b/test/test-stack.s
@@ -1,6 +1,6 @@
init:
cps
- ldx.w #$FFFF
+ ldx.d #$2FFFF
txs
tax
loop:
@@ -22,4 +22,3 @@ loop:
a
done
-