Delete a DIM'd array

Basic and Machine Language

Moderator: Moderators

Post Reply
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Delete a DIM'd array

Post by wimoos »

Hi all,

Unfortunately, I couldn't make this part of WimBasic. But the code is fully relocatable, so this opens up possibilities.
The tapebuffer is large enough to hold the code. I ran some tests now and it works as expected.

Removing an array can be useful when memory is scarce, or when an array needs redimensioning.

Deleting all arrays in one blow can be done with: DOKE $31, DEEK($2F) in WimBasic, or POKE 49,PEEK(47):POKE 50,PEEK(48) in CBM Basic

EDIT: After some effort, I did manage to make ERASE a new command in WimBasic. It takes a list of array names as parameter. ERASE replaces the TOGGLE command.
2ND EDIT: After some more effort, I managed to include the TOGGLE command again.

Regards,

wimoos

Code: Select all

;
;;
; 
; Routine to erase a DIMed array
; Can be loaded in the tape buffer
; Then, SYS828,<arrayname and type>
; does the trick
; 
	.org $033c
LD091	JSR     $CEFD		; skip comma and get first character
	JSR	$D113		; check byte, return Cb = 0 if<"A" or >"Z"
	BCS	LD09F		; if ok continue
LD095	JMP	$CF08		; else syntax error then warm start

LD09F	STA	$45		; save 1st character
	JSR	$0073		; increment and scan memory, 2nd character
	BCC	LD0AF		; if character = "0"-"9" (ok) go save 2nd character
	LDX	#$00
	JSR	$D113		; check byte, return Cb = 0 if<"A" or >"Z"
	BCC	LD0BA		; if <"A" or >"Z" go check if string
LD0AF	TAX				; copy 2nd character
LD0B0	JSR	$0073		; increment and scan memory, 3rd character
	BCC	LD0B0		; loop if character = "0"-"9" (ignore)
	JSR	$D113		; check byte, return Cb = 0 if<"A" or >"Z"
	BCS	LD0B0		; loop if character = "A"-"Z" (ignore)
LD0BA	CMP	#'$'			; compare with "$"
	BEQ     LD0D4
	CMP	#$25			; compare with "%"
	BNE	LD0DB		; if not integer go check for an array
	LDA	#$80			; set integer type
	ORA	$45		; OR current variable name first byte
	STA	$45		; save current variable name first byte
LD0D4	TXA				; get 2nd character back
	ORA	#$80			; set top bit, indicate string or integer variable
	TAX				; copy back to 2nd character temp
	JSR     $0073		; skip datatype identifier
LD0DB	STX	$46		; save 2nd character
;
; Name of array and arraytype is now read.
; 
	JSR     $0079
	BNE	LD095
;
; We know now there's no syntax error. Start searching for the array.
; 
	LDX	$2F		; set end of variables low byte
	LDA	$30		; set end of variables high byte
LD21C	CMP	$32		; compare with end of arrays high byte
	BNE	LD228		; if not reached array memory end continue searching
	CPX	$31		; else compare with end of arrays low byte
	BEQ	LD261		; array not found - leave silently
LD228	STX	$5F		; save as array start pointer low byte
	STA	$60		; save as array start pointer high byte
	LDY     #$00
	LDA	($5F),Y		; get array name first byte
	INY				; increment index to second name byte
	CMP	$45		; compare with this array name first byte
	BNE	LD237		; if no match go try the next array
	LDA	$46		; else get this array name second byte
	CMP	($5F),Y		; compare with array name second byte
;
; Found an array, determine pointer to next, already.
; Z-flag says this the target or not - we'll see to that later
; 
LD237	PHP
	INY				; increment index
	LDA	($5F),Y		; get array size low byte
	CLC				; clear carry for add
	ADC	$5F		; add array start pointer low byte
	TAX				; copy low byte to X
	INY				; increment index
	LDA	($5F),Y		; get array size high byte
	ADC	$60		; add array memory pointer high byte
	PLP
	BNE	LD21C		; not the target, set up for the next
;
; Tartget is found - move all the next arrays forward, if any
;
	STX	$61
	STA 	$62
	LDY	#$00
LD240	LDA	$61
	CMP	$31
	LDA	$62
	SBC	$32
	BCS	LD260
LD243	LDA	($61),Y
	STA	($5F),Y
	INC	$5F
	BNE	LD244
	INC	$60
LD244	INC	$61
	BNE	LD240
	INC	$62
	BNE	LD240		; branch always
	
LD260	LDA	$5F
	STA	$31
	LDA	$60
	STA	$32
LD261	RTS	
	.end

Last edited by wimoos on Mon Jul 18, 2022 1:54 am, edited 11 times in total.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
TRIANGULAR OS
Vic 20 Dabbler
Posts: 87
Joined: Wed Mar 09, 2022 4:53 am
Website: https://www.youtube.com/@triangular_uos
Location: Cracow, Poland

Re: Delete one or more DIMmed arrays

Post by TRIANGULAR OS »

WimBasic is great. But it takes me awhile to find download link on Your site hehe :)
I am wondering if it possible to make 16KB cartridge with WimBasic + my TRIANGULAR OS (once it reach ML phase)?
TRIANGULAR μOS for VIC-20:
http://www.sleepingelephant.com/ipw-web ... =2&t=10352

TRIANGULAR μOS YouTube channel:
https://www.youtube.com/@triangular_uos
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Delete one or more DIMmed arrays

Post by wimoos »

PM sent
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Delete one or more DIMmed arrays

Post by wimoos »

I did some minor concessions on the previous version of WimBasic to make space for this new command. The current version now supports the ERASE command. The concessions are that the TOGGLE command is removed and that MERGE no longer prints the text 'MERGING'.

ERASE removes a previously dimensioned array from memory at runtime. This is useful when 1) memory becomes scarce, 2) when an array needs to be redimensioned or 3) when it needs to be reinitialized with zeroes or empty strings.
Any dangling string elements are cleaned up by the next garbage collection.

Regards,

wimoos.
Last edited by wimoos on Sun Jun 26, 2022 11:49 am, edited 1 time in total.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Delete one or more "DIMmed" arrays

Post by Mike »

Just as an aside note - CBM BASIC features the error message "?REDIM'D ARRAY", the apostrophe signifying a contraction of the rather unwieldy word "REDIMENSIONED". It neither stands for "REDIMMED" nor "REDIMED".
Post Reply