From 692890787725595746d7b81c487178f3be314fc5 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 24 Jul 2020 21:24:45 +0200 Subject: [PATCH] reworked current array creation code (idea was wrong), compilation fix in Kernal --- src/basic/engine_variables/array_create.s | 100 +++++++++++++++------- src/kernal/rs232/rs232_count_channels.s | 4 +- 2 files changed, 70 insertions(+), 34 deletions(-) diff --git a/src/basic/engine_variables/array_create.s b/src/basic/engine_variables/array_create.s index 811de49a..14558871 100644 --- a/src/basic/engine_variables/array_create.s +++ b/src/basic/engine_variables/array_create.s @@ -12,54 +12,90 @@ array_create: // XXX check if the array already exists - // It will be easier if we first perform garbage collection (arrays are not declared often) + // Push variable name and FOUR6 on the stack - fetching dimensions might cause + // the to be overwritten by the expression parser + + lda VARNAM+0 + pha + lda VARNAM+1 + pha + lda FOUR6 + pha + + // Push 0 to mark end of the dimensions + + lda #$00 + pha + + // Now check if the array dimension is given - if not, assume '10' was specified + + bit DIMFLG + bmi array_create_fetch_dims + + lda #$0A + pha + bne array_create_store_dims // branch always + +array_create_fetch_dims: + + // XXX check if stack has reasonable space free + + // Fetch the dimension, put it on the stack - confirmed with orioginal ROM, + // that it also stores dimensions in the reverse order + + jsr fetch_uint8 + bcs_16 do_SYNTAX_error + pha + + // Check if more dimensions are given + + jsr fetch_character_skip_spaces + cmp #$2C // ',' + beq array_create_fetch_dims + cmp #$29 // ')' + bne_16 do_SYNTAX_error + + // FALLTROUGH + +array_create_store_dims: + + // We got the dimensions, time to alocate memory. Arrays are not declared too often, + // it will be easier if we perform the garbage collection now jsr varstr_garbage_collect - // Now, create the array structure + // Create the initial array structure - lda STREND+0 - sta INDEX+0 - lda STREND+1 - sta INDEX+1 + // Bytes 0/1 - array name, but we can not fetch it easily now, so skip it + // Bytes 2/3 - offset to the next array - our will be the last one, so 0 - but we will set it later + // Byte 4 - number of dimensions, determine it + // Bytes 5+ - size in each dimension - // XXX check if there is enough distance between INDEX and FRETOP + // INDEX+2/+3 will be used to calculate number of 'records' - // Store: - // - the array name (2 bytes) - // - offset to the next array (2 bytes) - 0 to mark the last one - // - initial array dimension - 0 + ldy #$01 + sty INDEX+3 + dey + sty INDEX+4 -#if CONFIG_MEMORY_MODEL_60K - - // XXX: implement this + ldy #$05 +!: + pla + beq array_create_store_num_dims -#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + // XXX implement this - ldy #$00 - lda VARNAM+0 - sta (STREND), y - iny - lda VARNAM+1 - sta (STREND), y - iny - lda #$00 - sta (STREND),y - iny - sta (STREND),y - iny - sta (STREND),y -#endif +array_create_store_num_dims: - // + // .Y contains number of dimensions + 5 + + // XXX rework code below - // XXX bit DIMFLG, bmi = use default params - // XXX jsr do_NOT_IMPLEMENTED_error diff --git a/src/kernal/rs232/rs232_count_channels.s b/src/kernal/rs232/rs232_count_channels.s index 49379a81..c4f17976 100644 --- a/src/kernal/rs232/rs232_count_channels.s +++ b/src/kernal/rs232/rs232_count_channels.s @@ -16,13 +16,13 @@ rs232_count_channels: ldy LDTND !: dey - bmi close_rs232_search_done + bmi !+ lda FAT, y cmp #$02 bne !- inx bpl !- // branch always - +!: rts