added memory checks and some other bits to array creation routine
This commit is contained in:
1 parent
07bbc21e50
commit
b7dee84390
3 files changed
+133
-63
No files matched your search
@@ -88,14 +88,21 @@ array_create_store_dims:
|
|||||||
phx_trash_a
|
phx_trash_a
|
||||||
jsr varstr_garbage_collect
|
jsr varstr_garbage_collect
|
||||||
|
|
||||||
// __FAC1+0/+1 will be used to calculate number of elements
|
// __FAC1+1/+2 will be used to calculate number of elements
|
||||||
|
|
||||||
ldy #$01
|
ldy #$01
|
||||||
sty __FAC1+0
|
|
||||||
dey
|
|
||||||
sty __FAC1+1
|
sty __FAC1+1
|
||||||
|
dey
|
||||||
|
sty __FAC1+2
|
||||||
|
|
||||||
// Create the initial array structure (format checked by creating arrays with original ROM)
|
// Check if there is enough free memory for the header
|
||||||
|
|
||||||
|
pla // .A - number of dimensions
|
||||||
|
sta __FAC1+0
|
||||||
|
jsr helper_array_create_checkmem
|
||||||
|
lda __FAC1+0
|
||||||
|
|
||||||
|
// Create the initial array structure (header) - format checked by creating arrays with original ROM
|
||||||
|
|
||||||
// Bytes 0/1 - array name, but we can not fetch it easily now, so skip it for now
|
// Bytes 0/1 - array name, but we can not fetch it easily now, so skip it for now
|
||||||
// Bytes 2/3 - offset to the next array, skip it for now too
|
// Bytes 2/3 - offset to the next array, skip it for now too
|
||||||
@@ -103,13 +110,15 @@ array_create_store_dims:
|
|||||||
// Bytes 5+ - max index in each dimension (big endian!), this will be set in a loop
|
// Bytes 5+ - max index in each dimension (big endian!), this will be set in a loop
|
||||||
|
|
||||||
ldy #$04
|
ldy #$04
|
||||||
pla
|
|
||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
|
||||||
// XXX
|
stx INDEX+2
|
||||||
// XXX: implement this
|
|
||||||
// XXX
|
ldx #<STREND
|
||||||
|
jsr poke_under_roms
|
||||||
|
|
||||||
|
ldx INDEX+2
|
||||||
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
|
||||||
@@ -118,7 +127,7 @@ array_create_store_dims:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
iny // .Y - index to store dimension sizes
|
iny // .Y - index to store dimension sizes
|
||||||
tax // .X - dimensions not sotred yet
|
tax // .X - dimensions not stored yet
|
||||||
|
|
||||||
// FALLTROUGH
|
// FALLTROUGH
|
||||||
|
|
||||||
@@ -126,19 +135,29 @@ array_create_store_loop:
|
|||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
|
||||||
// XXX
|
stx INDEX+2
|
||||||
// XXX: implement this
|
ldx #<STREND
|
||||||
// XXX
|
|
||||||
|
pla
|
||||||
|
jsr poke_under_roms
|
||||||
|
sta __FAC1+4
|
||||||
|
iny
|
||||||
|
pla
|
||||||
|
jsr poke_under_roms
|
||||||
|
sta __FAC1+3
|
||||||
|
iny
|
||||||
|
|
||||||
|
ldx INDEX+2
|
||||||
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
|
||||||
pla
|
pla
|
||||||
sta (STREND), y
|
sta (STREND), y
|
||||||
sta __FAC1+3
|
sta __FAC1+4
|
||||||
iny
|
iny
|
||||||
pla
|
pla
|
||||||
sta (STREND), y
|
sta (STREND), y
|
||||||
sta __FAC1+2
|
sta __FAC1+3
|
||||||
iny
|
iny
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -156,12 +175,14 @@ array_create_store_dims_done:
|
|||||||
|
|
||||||
pha
|
pha
|
||||||
sta FOUR6 // XXX do we need to store this value in FOUR6? is it still needed?
|
sta FOUR6 // XXX do we need to store this value in FOUR6? is it still needed?
|
||||||
sta __FAC1+2
|
sta __FAC1+3
|
||||||
stx __FAC1+3 // .X is 0 at this point
|
stx __FAC1+4 // .X is 0 at this point
|
||||||
|
|
||||||
jsr helper_array_create_mul
|
jsr helper_array_create_mul
|
||||||
|
|
||||||
// XXX check if we have enough memory
|
// Check if there is enough free memory
|
||||||
|
|
||||||
|
jsr helper_array_create_checkmem
|
||||||
|
|
||||||
// Retrieve and store array name
|
// Retrieve and store array name
|
||||||
|
|
||||||
@@ -169,9 +190,13 @@ array_create_store_dims_done:
|
|||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
|
||||||
// XXX
|
ldx #<STREND
|
||||||
// XXX: implement this
|
|
||||||
// XXX
|
pla
|
||||||
|
jsr poke_under_roms
|
||||||
|
iny
|
||||||
|
pla
|
||||||
|
jsr poke_under_roms
|
||||||
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
|
||||||
@@ -188,33 +213,20 @@ array_create_store_dims_done:
|
|||||||
lda #$02
|
lda #$02
|
||||||
jsr helper_INDEX_up_A
|
jsr helper_INDEX_up_A
|
||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
lda __FAC1+0
|
||||||
|
|
||||||
// XXX
|
|
||||||
// XXX: implement this
|
|
||||||
// XXX
|
|
||||||
|
|
||||||
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
|
||||||
|
|
||||||
// XXX
|
|
||||||
// XXX: implement this
|
|
||||||
// XXX
|
|
||||||
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K
|
|
||||||
|
|
||||||
ldy #$04
|
|
||||||
lda (STREND), y
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
asl
|
asl
|
||||||
jsr helper_INDEX_up_A
|
jsr helper_INDEX_up_A
|
||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
|
||||||
|
// .X already contains STREND
|
||||||
|
|
||||||
// XXX
|
ldy #$02
|
||||||
// XXX: implement this
|
lda INDEX+0
|
||||||
// XXX
|
jsr poke_under_roms
|
||||||
|
iny
|
||||||
|
lda INDEX+1
|
||||||
|
jsr poke_under_roms
|
||||||
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
|
||||||
@@ -227,11 +239,7 @@ array_create_store_dims_done:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clear newly alocated area
|
// Clear newly alocated area, adjust STREND
|
||||||
|
|
||||||
// XXX implement this
|
|
||||||
|
|
||||||
// Adjust STREND
|
|
||||||
|
|
||||||
// XXX implement this
|
// XXX implement this
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// #LAYOUT# STD * #TAKE
|
||||||
|
// #LAYOUT# * BASIC_0 #TAKE
|
||||||
|
// #LAYOUT# * * #IGNORE
|
||||||
|
|
||||||
|
//
|
||||||
|
// Checks if there is enough memory free for array
|
||||||
|
//
|
||||||
|
// Input:
|
||||||
|
// __FAC1+0 - number of dimensions
|
||||||
|
// __FAC1+1/+2 - bytes needed for storage
|
||||||
|
//
|
||||||
|
// Uses INDEX+2/+3, preserves .X and .Y
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
helper_array_create_checkmem:
|
||||||
|
|
||||||
|
// First calculate FRETOP - STREND
|
||||||
|
|
||||||
|
sec
|
||||||
|
lda FRETOP+0
|
||||||
|
sbc STREND+0
|
||||||
|
sta INDEX+2
|
||||||
|
lda FRETOP+1
|
||||||
|
sbc STREND+1
|
||||||
|
sta INDEX+3
|
||||||
|
bcc helper_array_create_checkmem_fail
|
||||||
|
|
||||||
|
// INDEX+2/+3 contains the amount of memory left, subtract the space needed for storage
|
||||||
|
|
||||||
|
lda INDEX+2
|
||||||
|
sbc __FAC1+1
|
||||||
|
sta INDEX+2
|
||||||
|
lda INDEX+3
|
||||||
|
sbc __FAC1+2
|
||||||
|
sta INDEX+3
|
||||||
|
bcc helper_array_create_checkmem_fail
|
||||||
|
|
||||||
|
// If high byte (INDEX+3) > 0, then we certainly have enough space
|
||||||
|
|
||||||
|
lda INDEX+3
|
||||||
|
bne helper_array_create_checkmem_success
|
||||||
|
|
||||||
|
// We have very little memory left - we need at least number of dimensions*2 + 5 bytes
|
||||||
|
|
||||||
|
lda __FAC1+0
|
||||||
|
asl
|
||||||
|
clc
|
||||||
|
adc #$04
|
||||||
|
|
||||||
|
cmp INDEX+2
|
||||||
|
bcs helper_array_create_checkmem_fail
|
||||||
|
|
||||||
|
// FALLTROUGH
|
||||||
|
|
||||||
|
helper_array_create_checkmem_success:
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
helper_array_create_checkmem_fail:
|
||||||
|
|
||||||
|
jmp do_OUT_OF_MEMORY_error
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// #LAYOUT# * BASIC_0 #TAKE
|
// #LAYOUT# * BASIC_0 #TAKE
|
||||||
// #LAYOUT# * * #IGNORE
|
// #LAYOUT# * * #IGNORE
|
||||||
|
|
||||||
// 16-bit multiplication, INDEX+0/+1 = __FAC1+0/+1 * __FAC1+2/+3; __FAC1+0/+1 = INDEX+0/+1
|
// 16-bit multiplication, INDEX+0/+1 = __FAC1+1/+2 * __FAC1+3/+4; __FAC1+1/+2 = INDEX+0/+1
|
||||||
// uses INDEX+2/+3 (for helper routine) as work area
|
// uses INDEX+2/+3 (for helper routine) as work area
|
||||||
|
|
||||||
|
|
||||||
@@ -12,37 +12,37 @@ helper_array_create_mul: // preserves .X and .Y
|
|||||||
|
|
||||||
// We will reuse 8x8 multiplication routine used by floating point operations
|
// We will reuse 8x8 multiplication routine used by floating point operations
|
||||||
|
|
||||||
// __FAC1+0 (lo byte) * __FAC1+2 (lo byte)
|
// __FAC1+1 (lo byte) * __FAC1+3 (lo byte)
|
||||||
|
|
||||||
lda __FAC1+0
|
lda __FAC1+1
|
||||||
sta INDEX+2
|
sta INDEX+2
|
||||||
lda __FAC1+2
|
lda __FAC1+3
|
||||||
jsr mul_FAC2_FAC1_8x8 // this preserves .Y
|
jsr mul_FAC2_FAC1_8x8 // this preserves .Y
|
||||||
|
|
||||||
sta INDEX+0 // result - lo byte
|
sta INDEX+0 // result - lo byte
|
||||||
stx INDEX+1 // result - hi byte
|
stx INDEX+1 // result - hi byte
|
||||||
|
|
||||||
// __FAC1+0 (lo byte) * __FAC1+3 (hi byte)
|
// __FAC1+1 (lo byte) * __FAC1+4 (hi byte)
|
||||||
|
|
||||||
lda __FAC1+0
|
|
||||||
sta INDEX+2
|
|
||||||
lda __FAC1+3
|
|
||||||
jsr helper_array_create_mul_8x8_add // multiply and add to high byte of the result
|
|
||||||
|
|
||||||
// __FAC1+1 (hi byte) * __FAC1+2 (lo byte)
|
|
||||||
|
|
||||||
lda __FAC1+1
|
lda __FAC1+1
|
||||||
sta INDEX+2
|
sta INDEX+2
|
||||||
lda __FAC1+2
|
lda __FAC1+4
|
||||||
jsr helper_array_create_mul_8x8_add // multiply and add to high byte of the result
|
jsr helper_array_create_mul_8x8_add // multiply and add to high byte of the result
|
||||||
|
|
||||||
// __FAC1+1 (hi byte) * __FAC1+3 (hi byte) has to be 0,
|
// __FAC1+2 (hi byte) * __FAC1+3 (lo byte)
|
||||||
|
|
||||||
|
lda __FAC1+2
|
||||||
|
sta INDEX+2
|
||||||
|
lda __FAC1+3
|
||||||
|
jsr helper_array_create_mul_8x8_add // multiply and add to high byte of the result
|
||||||
|
|
||||||
|
// __FAC1+2 (hi byte) * __FAC1+4 (hi byte) has to be 0,
|
||||||
// otherwise the result would be out of range
|
// otherwise the result would be out of range
|
||||||
// do not calculate
|
// do not calculate
|
||||||
|
|
||||||
lda __FAC1+0
|
lda __FAC1+2
|
||||||
beq helper_array_create_mul_success
|
beq helper_array_create_mul_success
|
||||||
lda __FAC1+3
|
lda __FAC1+4
|
||||||
beq helper_array_create_mul_success
|
beq helper_array_create_mul_success
|
||||||
|
|
||||||
// FALLTROUGH
|
// FALLTROUGH
|
||||||
|
|||||||
Reference in new issue
Block a user