I want to write the OS for the SD Card (OSISDOS) in C so it can be ported to other hardware platforms.
I tried to get the CC65 Assembler to work in a previous log and gave up. Let's try again. Here's the doc page (Ohio Scientific-specific information for cc65). From the page:
- The target "osic1p" is implemented
- The standard binary output format generated by the linker for the osic1p target is a pure machine language program.
- Example for converting an executable "hello" file that was built for the default start address $0200 to an uploadable file "hello.c1p":
srec_cat hello -bin -of 0x200 -o hello.c1p -os -esa=0x200
- By default programs compiled for the osic1p target are configured for 32 kB RAM. The RAM size can be configured via the symbol
__HIMEM__
. - The default start address is $0200. The start address is configurable via the linker option
--start-addr
. - The C runtime stack is located at the top of RAM and growing downwards. The size is configurable via the symbol
__STACKSIZE__
. The default stack size is $0400. - The C heap is located at the end of the program and grows towards the C runtime stack.
- Example for building a program with start address $0300, stack size $0200 and RAM size $2000:
cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p hello.c
- Default config file (
osic1p.cfg
) - This configuration is made for assembler programmers who don't need a special setup.
To use this config file, assemble with-t osic1p
and link with-C osic1p-asm.cfg
. The former will make sure that correct runtime library is used, while the latter supplies the actual config. When usingcl65
, use both command line options. Sample command lines forcl65
: -
cl65 -t osic1p -C osic1p-asm.cfg -o program source.s cl65 -t osic1p -C osic1p-asm.cfg -u __BOOT__ -o program.lod source.s
- Programs containing Ohio Scientific-specific code may use the
osic1p.h
header file. - There is a module
screen-c1p-24x24.o
in the OSI-specific cc65 runtime library that contains all conio functions that depend on the screen layout. No further configuration is needed for using the default screen layout of the Challenger 1P. - There is no support for stdio
- The program return code has no effect. When the main() function finishes, the boot prompt is shown again.
References
- cc65 Main Page
- OSI C1P Specific
- CC65 Wiki page
- DOS command line toolchain (my GitHub)
- CC65 Source Code
- Windows Snapshot
- cc65 Documentation Overview
Added bin folder of cc65 to PATH env vars.
Using Command line:
cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p -o OSISDOS.o OSISDOS.c
Create a list file:
cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p -l osidos.lst OSISDOS.c
No errors
Looking at command line options
--start-addr 0x300 = Set the default start address -Wl = Pass options directly to the linker. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by commas; the commas are replaced by spaces when passing them to the linker. -D,__HIMEM__=$2000, = Define a preprocessor symbol - 16K High Memory -D,__STACKSIZE__=$0200 = Define a preprocessor symbol - 512 byte stack -t osic1p = Set the target system - ISI C1P target
Change format
"..\..\..\..\..\PC Tools\srecord\srec_cat.exe" OSISDOS -bin -of 0x300 -o OSISDOS.c1p -os -esa=0x300
Output looks like:
.0300/A2 FF 9A D8 A9 00 A2 ...
Very nice!
Except this doesn't match the list file. Disassemble the object file using retroassembler disassemble function:
"C:\Users\HPz420\Documents\GitHub\Doug Gilliland\Retro-Computers\6502\RetroAssembler\retroassembler.exe" -d -D=0x0300 OSISDOS.o OSISDOS.DIS
The top of the file looks like:
$0300 a2 ff ldx #$ff $0302 9a txs $0303 d8 cld $0304 a9 00 lda #$00 $0306 a2 20 ldx #$20 $0308 85 02 sta $02 $030a 86 03 stx $03 $030c 20 9b 05 jsr $059b $030f 20 1b 03 jsr $031b $0312 20 27 03 jsr $0327 $0315 20 c1 04 jsr $04c1 $0318 4c 00 ff jmp $ff00 $031b a0 00 ldy #$00 $031d f0 07 beq $0326 $031f a9 27 lda #$27 $0321 a2 03 ldx #$03 $0323 4c be 05 jmp $05be $0326 60 rts
It's definitely 6502 code. Is that C1P startup code? The list file from cl65 has:
000000r 1 .forceimport __STARTUP__ 000000r 1 .export _main 000000r 1 .export _setLBA0 000000r 1 .export _setLBA1
Disappointing that the cl65 listing file does not contain all of the code that is created.
Create a map file using the line:
cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p -m OSISDOS.map -o OSISDOS.o OSISDOS.c
Table shows where main() starts:
Exports list by name: --------------------- __BSS_RUN__ 0005E3 RLA __BSS_SIZE__ 000000 REA __CONSTRUCTOR_COUNT__ 000000 REA __CONSTRUCTOR_TABLE__ 000327 RLA __DESTRUCTOR_COUNT__ 000000 REA __DESTRUCTOR_TABLE__ 0005BE RLA __MAIN_SIZE__ 001B00 REA __MAIN_START__ 000300 RLA __STACKSIZE__ 000200 REA __STARTUP__ 000001 REA _main 000327 RLA addysp 0004B4 RLA boolne 00051E RLA boolult 00053D RLA decsp1 0004CD RLA decsp4 0004D6 RLA donelib 0004C1 RLA incax1 0004E3 RLA incsp1 0004EA RLA incsp2 0004F9 RLA incsp4 000507 RLA initlib 00031B RLA ldauidx 00050C RLA ldaxysp 000517 RLA ptr1 00000A RLZ pusha 00054E RLA pushax 000564 RLA regsave 000006 RLZ sp 000002 RLZ staspidx 00057A RLA staxysp 000592 RLA tmp1 000012 RLZ zerobss 00059B RLA
main() is at 0x0327. The code at 0x0327 is:
$0327 a2 00 ldx #$00 $0329 a9 00 lda #$00 $032b 8d 05 f0 sta $f005 $032e a9 00 lda #$00 $0330 20 41 03 jsr $0341 $0333 a9 00 lda #$00 $0335 20 51 03 jsr $0351
This does nicely match the main() code is the .lst file from cl65:
000000r 1 A2 00 ldx #$00 000002r 1 A9 00 lda #$00 000004r 1 8D 05 F0 sta $F005 000007r 1 A9 00 lda #$00 000009r 1 20 rr rr jsr _setLBA0 00000Cr 1 A9 00 lda #$00 00000Er 1 20 rr rr jsr _setLBA1 000011r 1 A9 00 lda #$00 000013r 1 20 rr rr jsr _setLBA2 000016r 1 20 rr rr jsr _readBlock 000019r 1 60 rts
A more detailed map file can be created using the command line:
cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p -vm -m OSISDOS.map -o OSISDOS.o OSISDOS.c
I will debug the code in another log.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.