DUMP

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

DUMP

Post by Jeff-20 »

I would like to find or make a small DUMP subroutine that could fit inside the tape buffer. I have Simon Rowe's explicated source code of the Programmer's Aide's DUMP below (omitting routines it calls). Is it possible? Anyone willing to take on this challenge? Or maybe a small routine already exists, and I am missing it.

Code: Select all

;***********************************************************************************;
;
; perform DUMP

L7861   JSR CPYWORD		; copy word in zero page
        .BYT VARTAB,TMPPTR	; copy start of variables to temporary pointer
L7866   LDA TMPPTR		; get temporary pointer low byte
        CMP ARYTAB		; compare with end of variables low byte
        LDA TMPPTR+1		; get temporary pointer high byte
        SBC ARYTAB+1		; subtract end of variables high byte
        BCC L7873		; more variables, continue

        JMP DOREADY		; set immediate mode and do BASIC warm start

L7873   LDY #$00		; clear .Y
        STY TMPSTO		; clear variable type flags
        INY			; increment index to second variable name byte
L7878   LDA (TMPPTR),Y		; get variable name byte
        ASL			; shift top bit into Cb
        ROL TMPSTO		; shift top bit into variable type
        LSR			; restore variable name byte, Cb was clear
        STA VARNAM,Y		; set variable name byte
        DEY			; decrement index
        BPL L7878		; loop for both variable name bytes

        LDX TMPSTO		; get variable type
        BEQ L78B1		; both top bits were clear, floating-point

        DEX
        BEQ L78F0		; first byte was set, second clear, invalid type

        DEX
        BEQ L78C9		; top bit of first byte was clear, string

	; integer variable

        JSR PRTVNAM		; display variable name
        LDA #'%'
        JSR $CB47		; display character
        LDA #'='
        JSR $CB47		; display character
        LDY #$02		; offset to value high byte
        LDA (TMPPTR),Y		; get value high byte
        PHA			; save value high byte
        INY			; increment to offset to value low byte
        LDA (TMPPTR),Y		; get value low byte
        TAY			; copy value low byte to .Y
        PLA			; restore value high byte
        JSR MAKFP		; convert fixed integer .A.Y to float FAC1
L78A8   JSR FLTASC		; convert FAC1 to ASCII string result in (.A.Y)
        JSR PRTSTR		; print null terminated string
        JMP L78ED		; print CR/LF

	; floating-point variable

L78B1   JSR PRTVNAM		; display variable name
        LDA #'='
        JSR $CB47		; display character
        JSR RETVP		; return variable
        LDA VARPNT		; get current variable address low byte
        LDY VARPNT+1		; get current variable address high byte
        JSR LODFAC		; unpack memory (.A.Y) into FAC1
        JMP L78A8		; convert FAC1 to ASCII and print

L78C6   .BYT $22,"=$"

	; string variable

L78C9   JSR PRTVNAM		; display variable name
        LDX #$02		; string length - 1
L78CE   LDA L78C6,X		; get string byte
        JSR $CB47		; display character
        DEX			; decrement index
        BPL L78CE		; loop until all done

        LDY #$04		; index to value address high byte
        LDA (TMPPTR),Y		; get value address high byte
        STA INDEX+1		; set utility pointer high byte
        DEY			; decrement to value address low byte
        LDA (TMPPTR),Y		; get value address low byte
        STA INDEX		; set utility pointer low byte
        DEY			; decrement to value length
        LDA (TMPPTR),Y		; get value length
        JSR $CB24		; print string from utility pointer
        LDA #$22		; double quote
        JSR $CB47		; display character
L78ED   JSR $CAD7		; print CR/LF
L78F0   JSR STOP		; scan the stop key
        BNE L78F8		; branch if not [STOP]

        JMP DOREADY		; set immediate mode and do BASIC warm start

L78F8   LDA SHFLAG		; get keyboard shift/control flag
        BNE L78F8		; loop while a modifier down

        CLC
        LDA TMPPTR		; get temporary pointer low byte
        ADC #$07		; add length of each variable definition
        STA TMPPTR		; set temporary pointer low byte
        BCC L7908		; no carry, skip high byte increment

        INC TMPPTR+1		; increment temporary pointer high byte
L7908   JMP L7866		; check if end of variables reached


;***********************************************************************************;
;
; display variable name

PRTVNAM
        LDA VARNAM		; get current variable name first byte
        JSR $CB47		; display character
        LDA VARNAM+1		; get current variable name second byte
        BEQ L7929		; skip if zero

        JMP $CB47		; display character


High Scores, Links, and Jeff's Basic Games page.
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: DUMP

Post by wimoos »

Hello Jeff,

Here is the source for DUMP in WimBasic that you can use as a headstart.
Note that DEFined functions are also registered between the regular variables. My routine filters them out.

Regards,

Wim

Code: Select all

;
; Main entry point for DUMP
;
LAF29	BNE  LAF95    	 ;
	LDA  $2D       	 
	LDY  $2E       	 
LAF2F	CPY  $30       	 
	BNE  LAF39     	 
	CMP  $2F       	 
LAF39	BCS  LAF95
	STA  $14
	STY  $15     	 
	ADC  #$02      	 
	BCC  LAF40     	 
	INY            	 
LAF40	STA  $22       	 
	STY  $23       	 
	JSR  LAF70     	 
	BMI  LAF64     	 
	JSR  LAFCE
	JSR  LPVAR     	 
	JSR  LA4CC
LAF64	LDA  $14       	 
	LDY  $15       	 
	CLC            	 
	ADC  #$07      	 
	BCC  LAF2F     	 
	INY            	 
	BNE  LAF2F
;
LPVAR	TXA            	 
	BMI  LAF96     	 
	TYA            	 
	BMI  LAFA6     	 
LAF58	JSR  $DBA6     	 
LAF5B	INY
	JMP  $DDD7
;
LAF70	LDY  #$00      	 
	LDA  ($14),Y   	 
	INY            	 
	TAX            	 
	BPL  LAF82     	 
	EOR  ($14),Y   	 
	BMI  LAF95     	 
	TXA            	 
	AND  #$7F      	 
LAF82	JSR  $FFD2     	 
	LDA  ($14),Y   	 
	TAY            	 
	AND  #$7F      	 
	BEQ  LAF8F     	 
	JSR  $FFD2     	 
LAF8F	TXA            	 
	BMI  LAFC8     	 
	TYA            	 
	BMI  LAFCB     	 
LAF95	RTS
;            	 
LAF96	LDY  #$00      	 
	LDA  ($22),Y   	 
	STA  $62            	 
	INY            	 
	LDA  ($22),Y   	 
	TAY            	        	 
	JSR  $D397     	 
	BVC  LAF5B     	 ; branch always
;
LAFA6	JSR  LAFC5     	 
	JSR  $D6B1
	JSR  $CB24
LAFC5	LDA  #$22      	 
	.BYTE $2C 	 
LAFC8	LDA  #'%'      	 
	.BYTE $2C 	 
LAFCB	LDA  #'$'      	 
LAFCC	JMP  $FFD2
;
LAFCD	JSR  $FFD2
LAFCE	LDA  #'='      	 
	BNE  LAFCC
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Re: DUMP

Post by Jeff-20 »

Thank you, friend! Off topic, are you really a farmer? I have the "typical urbanite" romantic view of that job.
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: DUMP

Post by Mike »

Here we go: dump.prg.

With MINIMON, I transferred the code from $AF11..$AF9F (where it actually is located in the WimBasic binary) to $033C and then applied my relocate routine. After NOPing out the first branch and vetting a stray JSR $AB80 at $0362 with a knapsack that prints a CR, everything seems to work ... fingers crossed. ;)

Don't forget to correct the BASIC pointers with NEW after LOAD"DUMP.PRG",8,1 - start the tool with SYS828.

Cheers,

Michael
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Re: DUMP

Post by Jeff-20 »

Mike wrote: Mon Dec 20, 2021 2:54 pm Here we go:
Cheers,

Michael
Mike, you're awesome! I'll try it out...
High Scores, Links, and Jeff's Basic Games page.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Re: DUMP

Post by Jeff-20 »

I put it into a BASIC type-in format for no useful reason at all, but I'll share:

Code: Select all

1 FORT=828TO1020:READA:POKET,A:B=B+A:NEXT:IFB<>22546THEN
  PRINT"ERROR"
2 DATA234,234,165,45,164,46,196,48,208,2,197,47,176,86,133,
  20,132,21,105,2,144,1,200
3 DATA133,34,132,35,32,126,3,48,9,32,199,3,32,113,3,32,203,
  3,165,20,164,21,24,105,7
4 DATA144,212,200,208,209,138,48,45,152,48,57,32,166,219,
  200,76,215,221,160,0,177,20
5 DATA200,170,16,7,81,20,48,22,138,41,127,32,210,255,177,
  20,168,41,127,240,3,32,210
6 DATA255,138,48,31,152,48,31,96,160,0,177,34,133,98,200,
  177,34,168,32,151,211,80,20
7 DATA32,185,3,32,177,214,32,36,203,169,34,44,169,37,44,
  169,36,76,210,255,32,210,255
8 DATA169,61,208,246,72,169,13,32,210,255,104,96,15,2,240,
  3,108,14,2,32,164,227,32,4
9 DATA228,162,251,154,76,116,196,152,72,162,8,160,0,177,
  251,145,253,136,208,249,230
10 DATA252,230,254,202,208,242,104,168,96
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: DUMP

Post by Mike »

Jeff-20 wrote:I put it into a BASIC type-in format for no useful reason at all, [...]
For small ML programs this is a perfectly legit method to distribute the software. I did quite the same here with early instances of MINIGRAFIK, before I put my stuff on cloud/web storage.

Your DATA loader included some extra data beyond the actual code of the utility, and there's at least one typo (the last number in line 6 should be 202, not 20). Here's a consolidated version, also with checksum (download):

Code: Select all

1 FORT=828TO978:READA:POKET,A:S=S+A:NEXT:IFS<>16561THENPRINT"CHECKSUM ERROR!"
2 DATA 234,234,165,45,164,46,196,48,208,2,197,47,176,86,133,20,132,21,105,2,144,1,200
3 DATA 133,34,132,35,32,126,3,48,9,32,199,3,32,113,3,32,203,3,165,20,164,21,24,105,7
4 DATA 144,212,200,208,209,138,48,45,152,48,57,32,166,219,200,76,215,221,160,0,177,20
5 DATA 200,170,16,7,81,20,48,22,138,41,127,32,210,255,177,20,168,41,127,240,3,32,210
6 DATA 255,138,48,31,152,48,31,96,160,0,177,34,133,98,200,177,34,168,32,151,211,80,202
7 DATA 32,185,3,32,177,214,32,36,203,169,34,44,169,37,44,169,36,76,210,255,32,210,255
8 DATA 169,61,208,246,72,169,13,32,210,255,104,96
Per default, VICE autostarts files with ",8,1" and this requires one to set the RAM config to unexpanded beforehand (I saved 'loader.prg' with $1001 as load address). A manual load with ",8" and RUN works in all RAM configs.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Re: DUMP

Post by Jeff-20 »

Thanks!
High Scores, Links, and Jeff's Basic Games page.
Post Reply