Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » drive error while opening buffer in assembly
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
drive error while opening buffer in assembly [message #4] Sat, 17 December 2011 10:41 Go to next message
Chris Cureau is currently offline  Chris Cureau
Messages: 3
Registered: December 2011
Karma: 0
Junior Member
From Newsgroup: comp.sys.cbm

I'm trying to write a small program that autostarts in the Commodore 128s Function ROM space that will read and execute a program from the disk drive. Trouble is, it's causing me a lot of pain and I'm not sure why. Yes, I know I can autostart on a 128, but I want to target other 8-bit Commodores too. :)

Basically, I'm opening the command channel, then attempting to open a buffer on channel 2. Then I send a U1 command to read track 18, sector 1 (just to test with.) This works fine from basic, but something isn't right in my assembly. When I read the channel after each open attempt, I get:

73,CBM DOS 2.6 1541,00,00
62, FILE NOT FOUND,00,00
70,NO CHANNEL,00,00

The buffer open returns the file not found!

I've pasted the relevant code below. If anyone would be kind enough to point me in the right direction, I'd be most appreciative!

I'm using the cc65 toolchain for development and simply targeting the c128 at this point.

Thanks,
Chris

--- BEGIN CODE ---


start_code:
lda #6 ;Kernal and Internal ROM (LOW), RAM(0), I/O
sta $d501 ;write to preconfiguration register A
sta $ff01 ;write to LCR A
sei ;disable interrupts
jsr CLALL ;close all files and channels

; set up command channel
lda #15 ;logical file number 15
ldx #8 ;device 8
ldy #15 ;secondary address 15
jsr SETLFS ;set LA, FA, SA
lda #0 ;zero length file name
jsr SETNAM
jsr OPEN ;open command channel
jsr readerr

; set up for random access
lda #2 ;logical file number 2
ldx #8 ;device 8
ldy #2 ;secondary address 2
jsr SETLFS ;set LA, FA, SA

lda #drvcmd-buffer
ldx # ldy #>buffer ;set file name
jsr SETNAM
jsr OPEN ;open command channel
jsr readerr

; grab info from Track 18, Sector 1 (block-read)
ldx #15 ;15 is active channel out
jsr CKOUT
ldx #0
ldy #endcmd-drvcmd ;length of file name (11 characters)
fname:
lda drvcmd,x ;pointer to file name
jsr BSOUT ;output to channel
inx
dey
bne fname ;loop to finish sending filename
jsr CLRCH ;restore default channel
jsr readerr
;
ldx #2 ;set 2 as active channel in
jsr CHKIN
ldx #0
rdloop:
jsr BASIN ;input from channel
rl1:
tya
sta $0400,x ;put to screen
inx
bne rdloop ;read 256 bytes
jsr CLRCH ;restore default channel
jsr CLALL ;close all channels
brk

; print i/o status routine
readerr:
ldx #15 ; command channel is input
jsr CHKIN
errl: jsr BASIN ; read from file

jsr BSOUT
cmp #$0d ; is this character a carriage return?
bne errl ; nope - keep reading
jsr CLRCH ; restore I/O
rts

; data
buffer:
.byte "#"
drvcmd:
.byte "U1 2 0 18 1"
endcmd:
readcnt:
.byte 0

--- END CODE ---
--- Synchronet 3.13a-Win32 NewsLink 1.83
Re: drive error while opening buffer in assembly [message #7 is a reply to message #4] Sun, 18 December 2011 01:06 Go to previous messageGo to next message
Anton Treuenfels is currently offline  Anton Treuenfels
Messages: 105
Registered: December 2011
Karma: 0
Senior Member
From Newsgroup: comp.sys.cbm

A quick look, not in great detail, suggests that your code does not use the
SETBANK routine prior to calling OPEN. It's possible that the name being
sent is different than the one you think is because the Kernel is reading
the name from the wrong bank.

Here's a link to an old issue of Transactor magazine that has an article,
'C128 Simple Disk Monitor', showing a short program that does direct access
reads and writes of disk blocks:

http://www.csbruce.com/cbm/transactor/v9/i5/

That program is known to work (I should know!).

- Anton Treuenfels



"Chris Cureau" wrote in message
news:17776445.240.1324136518832.JavaMail.geo-discussion-foru ms@yqni12...
I'm trying to write a small program that autostarts in the Commodore 128s
Function ROM space that will read and execute a program from the disk drive.
Trouble is, it's causing me a lot of pain and I'm not sure why. Yes, I know
I can autostart on a 128, but I want to target other 8-bit Commodores too.
:)

Basically, I'm opening the command channel, then attempting to open a buffer
on channel 2. Then I send a U1 command to read track 18, sector 1 (just to
test with.) This works fine from basic, but something isn't right in my
assembly. When I read the channel after each open attempt, I get:

73,CBM DOS 2.6 1541,00,00
62, FILE NOT FOUND,00,00
70,NO CHANNEL,00,00

The buffer open returns the file not found!

I've pasted the relevant code below. If anyone would be kind enough to
point me in the right direction, I'd be most appreciative!

I'm using the cc65 toolchain for development and simply targeting the c128
at this point.

Thanks,
Chris

--- BEGIN CODE ---


start_code:
lda #6 ;Kernal and Internal ROM (LOW), RAM(0), I/O
sta $d501 ;write to preconfiguration register A
sta $ff01 ;write to LCR A
sei ;disable interrupts
jsr CLALL ;close all files and channels

; set up command channel
lda #15 ;logical file number 15
ldx #8 ;device 8
ldy #15 ;secondary address 15
jsr SETLFS ;set LA, FA, SA
lda #0 ;zero length file name
jsr SETNAM
jsr OPEN ;open command channel
jsr readerr

; set up for random access
lda #2 ;logical file number 2
ldx #8 ;device 8
ldy #2 ;secondary address 2
jsr SETLFS ;set LA, FA, SA

lda #drvcmd-buffer
ldx # ldy #>buffer ;set file name
jsr SETNAM
jsr OPEN ;open command channel
jsr readerr

; grab info from Track 18, Sector 1 (block-read)
ldx #15 ;15 is active channel out
jsr CKOUT
ldx #0
ldy #endcmd-drvcmd ;length of file name (11 characters)
fname:
lda drvcmd,x ;pointer to file name
jsr BSOUT ;output to channel
inx
dey
bne fname ;loop to finish sending filename
jsr CLRCH ;restore default channel
jsr readerr
;
ldx #2 ;set 2 as active channel in
jsr CHKIN
ldx #0
rdloop:
jsr BASIN ;input from channel
rl1:
tya
sta $0400,x ;put to screen
inx
bne rdloop ;read 256 bytes
jsr CLRCH ;restore default channel
jsr CLALL ;close all channels
brk

; print i/o status routine
readerr:
ldx #15 ; command channel is input
jsr CHKIN
errl: jsr BASIN ; read from file

jsr BSOUT
cmp #$0d ; is this character a carriage return?
bne errl ; nope - keep reading
jsr CLRCH ; restore I/O
rts

; data
buffer:
.byte "#"
drvcmd:
.byte "U1 2 0 18 1"
endcmd:
readcnt:
.byte 0

--- END CODE ---

--- Synchronet 3.13a-Win32 NewsLink 1.83
Re: drive error while opening buffer in assembly [message #32 is a reply to message #7] Sun, 18 December 2011 17:14 Go to previous message
Chris Cureau is currently offline  Chris Cureau
Messages: 3
Registered: December 2011
Karma: 0
Junior Member
From Newsgroup: comp.sys.cbm

Anton,

Amazing - that one missed routine (SETBNK) had me scratching my head for the longest time! Thank you for pointing it out!!! And I'm glad its not too late in the game for people in the Commodore community to help out. :)
--- Synchronet 3.13a-Win32 NewsLink 1.83
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Free sexy Games and Apps Girls
Next Topic: FA: Amiga 500 & monitors (Sydney)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Sep 28 00:16:53 EDT 2022

Total time taken to generate the page: 0.02952 seconds