OSI Disk Re-creation Project

Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

OSI Disk Re-creation Project

Post by Jeff »

I am working on a two part project. The first part is a small program that runs on a Challenger that takes commands and data from a host (Mac, PC, Etc) that will send it disk track and sector data for the purposes of re-constructing floppy disks.

Here is my first cut for the Challenger slave portion.

Code: Select all

;
; 	IMG2DISK FOR OSI
;	Version 0.1
;	Jeff Ferguson
;	June 2015
;
; 	Requires DOS loaded at $2200 - $3200
;
;

        .setcpu "6502"

; hardware locations
ACIAControl 	:= $FC00	; ON A C4PMF
ACIAData 		:= $FC01	; ON A C4PMF
DiskPIA			:= $C000	; DISK CONTROLLER
ExitVector		:= $FFFC	;

; locations of DOS variables and params
PagesToWrite	:= $265F
SectorToWrite	:= $265E
TrackToWrite	:= $2662
DriveToWrite	:= $265C
WriteBufferHi	:= $2661
WriteBufferLo	:= $2660

; callable DOS functions
WriteSector		:= $27D7
MoveToSector	:= $28C4
MoveToTrack		:= $26A6
LoadHead		:= $2754
LiftHead		:= $2761

CR			:= $0D
LF			:= $0A
IMGCMD		:= $49
EXITCMD		:= $45
ATTN		:= $2A
zpPages		:= $F0
zpBufferHi	:= $F2
zpBufferLo	:= $F1
DataBuffHi	:= $40
DataBuffLo	:= $00

; ----------------------------------------------------------------------------
	.ORG  	$0400
; ----------------------------------------------------------------------------
Enter:	
	JSR		SendInlineBytesToHost
	.BYTE	CR,LF
	.BYTE	"OSI CLIENT  v0.1",CR,LF,CR,LF,CR,LF,CR,LF
	.BYTE	"READY",CR,LF,0

@ready:
	JSR		GetCommand
	LDA		CommandIn
	BEQ		@ready
	CMP		#IMGCMD				;Host is sending an Image
	BEQ		@handleImage
	CMP		#EXITCMD			;Host is done talking
	BEQ		@handleExit
	JMP 	@ready
	
@handleImage:
	JSR 	LoadImage
	JMP 	@ready
	
@handleExit:
Quit:
	JMP		(ExitVector)
	
; ----------------------------------------------------------------------------
LoadImage:
	LDA		PagesIn
	STA		zpPages				; page count
	LDA		#DataBuffHi			; buffer high
	STA		zpBufferHi			; vector high
	LDA		#DataBuffLo			; buffer low
	STA		zpBufferLo			; vector low
	LDY		#$0					; y counter
@loop:
	JSR		GetByteFromHost
	STA		(zpBufferHi),Y
	INY
	BNE		@loop
	INC		zpBufferLo
	DEC		zpPages
	BNE		@loop

SaveImage:
	; Place Head on Disk
	JSR		LoadHead
	
	; Move to Track TRACK
	LDA		TrackIn
	STA		TrackToWrite		; Track needs to be in decimal
	LDA 	#$0					; Drive Number
	STA 	DriveToWrite
	JSR		MoveToTrack			; Move Head To Track
	
	; Move to Sector SECTOR
	LDA		SectorIn
	STA		SectorToWrite
	JSR		MoveToSector
	
	; Write Sector (Pages count??)
    LDA 	#DataBuffLo
    STA 	WriteBufferLo
    LDA 	#DataBuffHi
    STA 	WriteBufferHi
    LDA 	SectorIn
    STA 	SectorToWrite
    LDA 	PagesIn
    STA 	PagesToWrite
	JSR		WriteSector
	
	; Lift Head
	JSR 	LiftHead
	
	JSR	SendInlineBytesToHost
	.BYTE	"DONE",CR,LF,0
	RTS

; ----------------------------------------------------------------------------
; Looks for Byte stream '***ITSP'
; Sets CommandIn to 0 or 'I', 0 = No Cmd
; Sets TrackIn to T
; Sets SectorIn to S
; Sets PagesIn to P
;
GetCommand:
	LDA		#$0
	STA		CommandIn			; store 'not found result'
	JSR 	GetByteFromHost
	CMP 	#ATTN				;*
	BNE		@done
	JSR 	GetByteFromHost
	CMP 	#ATTN				;*
	BNE		@done
	JSR 	GetByteFromHost
	CMP 	#ATTN				;*
	BNE		@done
	JSR 	GetByteFromHost
	CMP 	#IMGCMD				;I
	BNE		@done
	STA		CommandIn			; store a non-zero command ('I')
	JSR 	GetByteFromHost
	STA		TrackIn				; read Track
	JSR 	GetByteFromHost
	STA		SectorIn			; read Sector
	JSR 	GetByteFromHost
	STA		PagesIn				; read Pages
@done:
	RTS
	
; ----------------------------------------------------------------------------
; Load a byte from the ACIA
; Result is in A
GetByteFromHost:
@loop:  
    LDA     ACIAControl         ; ACIA Status Register
    LSR     A                   ; Is there a byte ready to be read in the read register?
    BCC     @loop           	; loop to read again
    LDA     ACIAData            ; read a byte from ACIA Data Register
    RTS                         ; return

; --------------------------------------------------------
; Send a null terminated bunch of bytes to the ACIA
; the bytes follow the originating JSR op-code that called us
SendInlineBytesToHost:	
	PLA							; get address of bytes on the stack
	STA		zpBufferHi			; - just happens to be our return address!
	PLA							;
	STA		zpBufferLo
	LDY		#1					; init Y
@loop:	
	LDA		(zpBufferHi),Y
	BEQ		@exit				; exit if byte is 0 (string terminator)
	JSR		PutByteToHost
	INY
	BNE		@loop
@exit:	
	TYA							; how many bytes we did
	SEC							; prepare for add
	ADC		zpBufferHi			; add Y to our return address
	STA		zpBufferHi			; and store it
	BCC		@out				; no carry...just jmp
	INC		zpBufferLo			; add the carry
@out:		
	JMP		(zpBufferHi)		; return to caller....following the inline bytes
	
; ----------------------------------------------------------------------------
; Save a byte to the ACIA
; byte to put is in A
PutByteToHost:
	JSR     SerialPortOut   	; serial port output
	RTS

; ----------------------------------------------------------------------------
; Save a byte to the ACIA
; byte to output is in A
SerialPortOut:
	PHA                     	; save A
@checkStatus:  
	LDA     ACIAControl     	; load ACIA Status register to see if a byte is ready to be read
	AND		#$02				; check the TDRE, bit 2... 1 indicates data register is still full
	BNE     @checkStatus    	; not sent yet, loop until its gone
	PLA                     	; restore A
	STA     ACIAData        	; send it on its way
	PHA                     	; save A
	LDA		#$04				; waste 4 bunches of time
	JSR		Delay				; waste a bunch of time
	PLA                     	; restore A
	RTS                     	; return to caller

; ----------------------------------------------------------------------------
; A contains length of delay
Delay:							; start a delay loop
	STA		DelayCount	
@loop:  
	DEC		DelayCount	
	CMP		DelayCount	
	BNE		@loop   
	RTS				

; ----------------------------------------------------------------------------
; Variable Storage
CommandIn:	.byte	0
TrackIn:	.byte	0
SectorIn:	.byte	0
PagesIn:	.byte	0
DelayCount:	.byte	0

; ============================================================================	

	.END
I haven't tested it yet. I am working on the host program now, and hopefully I will have something that takes an OSI image file, same one as the WinOSI emulator, and sends it to the Challenger for re-construction, fairly soon.

If there are any 6502 assembly guru's out there with spare brain cycles and would like to improve the code, feel free, and re-post your changes. If we crowd-code, maybe it will happen sooner!

/Jeff
Image
BillO
Posts: 217
Joined: Tue Jul 08, 2014 4:03 pm
Location: Canada

Re: OSI Disk Re-creation Project

Post by BillO »

Cool!

What assembler are you using?
Box stock Superboard II Rev. B
KLyball replica 600D, replica 610 & KLyball Data Separator
OMS SBME and SBME+ memory cards
OMS Digi-Mule expansion bus
KLyball memory card
Klyball
Posts: 237
Joined: Tue Dec 09, 2014 12:53 am

Re: OSI Disk Re-creation Project

Post by Klyball »

Double cool !!, I would also like to know your assembler I had to change the syntax for my compilers
Replica 600 Rev D:8K,CEGMON
Replica 610 Rev B: 24k,MPI B-51 with Custom Data separator D-13
510 on the bench/replica 582 backplane/replica 470a /replica 555/original 570B/2 x Shugart 851
Ongoing : 630 ,620 ,510,542c,custom 590,SA1200,592,594,596,598
Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

Re: OSI Disk Re-creation Project

Post by Jeff »

I am using the macro assembler that is part of this program: http://www.cc65.org

I haven't figured out how to get the c compiler up and running yet, though.

/Jeff
Image
stm
Posts: 63
Joined: Mon Oct 27, 2014 10:23 pm
Location: Germany

Re: OSI Disk Re-creation Project

Post by stm »

Hi Jeff,
Jeff wrote:I am using the macro assembler that is part of this program: http://www.cc65.org

I haven't figured out how to get the c compiler up and running yet, though.
please note that http://www.cc65.org is outdated and no longer maintainted. The live page is http://cc65.github.io/cc65/. From there you can also find the OSI-specific documentation.

What problems do you have with the cc65 C compiler?

Stephan
C1P Model 600 CPU 1978 REV B, 40K (8K original and 32K BillO memory expansion), RS-232
Maintainer of cc65 OSI target and llvm-mos-sdk C1P target
Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

Re: OSI Disk Re-creation Project

Post by Jeff »

Thanks for the info Stephen.

There doesn't seem to be a version there that will compile and run under Mac OS X, which is what I am using.

I got as far as compiling a simple program using 2.13.3, but the linker cant find things like __STARTUP__ among others. I guess I am going to have to dig into the internal workings of it to get it to go. Im just using a target of none.

I compile for both C4P and C1P, which have different keyboard maps, rom routine maps, screen differences and I/O port differences.

/Jeff
Image
stm
Posts: 63
Joined: Mon Oct 27, 2014 10:23 pm
Location: Germany

Re: OSI Disk Re-creation Project

Post by stm »

Jeff wrote: There doesn't seem to be a version there that will compile and run under Mac OS X, which is what I am using.

I got as far as compiling a simple program using 2.13.3, but the linker cant find things like __STARTUP__ among others. I guess I am going to have to dig into the internal workings of it to get it to go. Im just using a target of none.
You should use the "osic1p" target.
Jeff wrote:I compile for both C4P and C1P, which have different keyboard maps, rom routine maps, screen differences and I/O port differences.
What concrete problems do you have when you try to compile the cc65 compiler under Mac OS X?

Please also take a look at my repository with C1P test programs, which includes a Makefile to build the test programs. Among others there is a make target for building an executable from only an assembler source file.

There's no support so far for the C4P, because I don't know enough about it. If you can provide the details I will be happy to extend cc65 with support for the C4P.

Stephan
C1P Model 600 CPU 1978 REV B, 40K (8K original and 32K BillO memory expansion), RS-232
Maintainer of cc65 OSI target and llvm-mos-sdk C1P target
Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

Re: OSI Disk Re-creation Project

Post by Jeff »

Hi Stephen,

The 2.13.3 version of cc65 does not have the osic1p target.

I don't see any instructions regarding how to compile cc65 on a mac. With 2.13.3 you typed

Code: Select all

 make -f make/gcc.mak
and then

Code: Select all

sudo make -f make/gcc.mak install
but those files are not present in the latest version
/Jeff
Image
Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

Re: OSI Disk Re-creation Project

Post by Jeff »

I found the instructions on how to make the package on OS X, but I get an error when I run the make.
Screen Shot 2015-07-05 at 4.39.47 PM.jpg
Screen Shot 2015-07-05 at 4.39.47 PM.jpg (175.96 KiB) Viewed 12709 times

It seems that someone left hard-coded directory structures in the make file.

/Jeff
Image
Jeff
Posts: 370
Joined: Fri Mar 07, 2014 4:44 am
Location: British Columbia, Canada

Re: OSI Disk Re-creation Project

Post by Jeff »

So. I added the directories in my user folder, and the package compiled. I think that the powers-that-be need to remove that requirement.

Now I am evaluating your sample programs and make files.
I would be happy to assist making a C4P target.
/Jeff
Image
Post Reply