Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Trying to create an IP65 based ROM, troubles with addressing/memconfig
2017-01-18 04:40
wbochar

Registered: May 2002
Posts: 26
Trying to create an IP65 based ROM, troubles with addressing/memconfig

Trying to create an IP65 based ROM, troubles with addressing/memconfig.

I'm used to Kick Assembler and before that I used TA.
I wanted to make something with a C64NIC+ cart, which means IP65 and ca65.

I have the ca65 env setup and everything works, the test programs compile and they work in hardware and emulation.

I want to relocate the the program to operate from $8009 (where the Cart Warm/Cold vectors will point to at $8000)
I have all the Cart and CRT header/code working in KA, so recreating it in ca65 shouldn't be too tough.

So I notice there is something injecting a basic stub to autorun the compiled code, I've read that __EXEHDR__ combined with c64.lib makes this happen. I've commented out EXEHDR in the cfg.

If I adjust the starting address to $8000, it will not assemble as the memory regions are wrong.
So I adjusted to the settings below, which assembles but will not run with SYS32768.

I am not sure how to handle this cfg file properly. I am used to a single file asm (or one or two includes) with pc counter directly adjusted *=$801 etc.


ld65 -o $*.prg -C c64.cfg -m $*.c64.map -vm $< $(IP65LIB) $(C64DRIVERLIB) c64.lib


FEATURES {
    STARTADDRESS: default = $8000;
}
SYMBOLS {
    __LOADADDR__:  type = import;
#    __EXEHDR__:    type = import;
    __STACKSIZE__: type = weak, value = $0800; # 2k stack
    __HIMEM__:     type = weak, value = $7700;
}
MEMORY {
    ZP:       file = "", define = yes, start = $0002,           size = $001A;
    LOADADDR: file = %O,               start = %S - 2,          size = $0002;
    HEADER:   file = %O, define = yes, start = %S,              size = $000D;
    MAIN:     file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__;
    BSS:      file = "",               start = __ONCE_RUN__,    size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
}
SEGMENTS {
    ZEROPAGE: load = ZP,       type = zp;
    LOADADDR: load = LOADADDR, type = ro;
#    EXEHDR:   load = HEADER,   type = ro;
    STARTUP:  load = MAIN,     type = ro;
    LOWCODE:  load = MAIN,     type = ro,  optional = yes;
    CODE:     load = MAIN,     type = ro;
    RODATA:   load = MAIN,     type = ro;
    DATA:     load = MAIN,     type = rw;
    INIT:     load = MAIN,     type = rw;
    ONCE:     load = MAIN,     type = ro,  define   = yes;
    BSS:      load = BSS,      type = bss, define   = yes;
}
FEATURES {
    CONDES: type    = constructor,
            label   = __CONSTRUCTOR_TABLE__,
            count   = __CONSTRUCTOR_COUNT__,
            segment = ONCE;
    CONDES: type    = destructor,
            label   = __DESTRUCTOR_TABLE__,
            count   = __DESTRUCTOR_COUNT__,
            segment = RODATA;
    CONDES: type    = interruptor,
            label   = __INTERRUPTOR_TABLE__,
            count   = __INTERRUPTOR_COUNT__,
            segment = RODATA,
            import  = __CALLIRQ__;
}



.include "../inc/common.i"
.include "../inc/commonprint.i"
.include "../inc/net.i"

.export start

.import exit_to_basic

.import print_a
.import get_key
.import ascii_to_native
.import parser_init
.import parser_skip_next
.importzp copy_src
.importzp copy_dest
.import url_ip
.import url_port
.import url_selector
.import url_resource_type
.import url_parse
.import url_download
.import url_download_buffer
.import url_download_buffer_length

temp_buff = copy_dest


; keep LD65 happy
.segment "INIT"
.segment "ONCE"



.segment "STARTUP"

  ; switch to lower case charset
  lda #14
  jsr print_a
  lda #0
  sta $d020
  sta $d021
start:
  jsr print_cr
  init_ip_via_dhcp
  jsr print_ip_config

  ldax #url_1
  jsr test_url_download

  ldax #url_2
  jsr test_url_download

  jmp exit_to_basic

test_url_download:
  stax temp_url_ptr
  ldax #downloading
  jsr print
  ldax temp_url_ptr
  jsr print
  jsr print_cr
  ldax #dl_buffer
  stax url_download_buffer
  ldax #dl_buffer_length
  stax url_download_buffer_length

  ldax temp_url_ptr
  jsr url_download
  bcc :+
  jmp print_errorcode
: ldax #dl_buffer
  jsr parser_init
@next_title:
  ldax #title
  jsr parser_skip_next
  bcs @done

  jsr print_tag_contents
  jsr print_cr

  jmp @next_title
@done:
  rts

wait_key:
  ldax #press_a_key
  jsr print
  jmp get_key

print_tag_contents:
  stax temp_buff
  lda #0
  sta string_offset
@next_byte:
  ldy string_offset
  lda (temp_buff),y
  beq @done
  cmp #'<'
  beq @done
  jsr ascii_to_native
  jsr print_a
  inc string_offset
  beq @done
  inc $d020
  jmp @next_byte
@done:
  rts


.data

title:
  .byte "<title>",0

url_1:
  .byte "http://wbochar.com/dl/test.txt",0
url_2:
  .byte "http://wbochar.com/dl/test.htm",0

downloading:
  .asciiz "DOWNLOADING "
press_a_key:
  .byte "PRESS ANY KEY TO CONTINUE",13,0


.bss

string_offset: .res 1
selector_ptr:  .res 2
temp_url_ptr:  .res 2

dl_buffer_length = 8092
dl_buffer: .res dl_buffer_length

2017-01-18 09:15
JackAsser

Registered: Jun 2002
Posts: 1987
Remove LOADADDR and HEADER alltogether firstly if you wanna make a .crt-file.
2017-01-19 23:42
wbochar

Registered: May 2002
Posts: 26
Quoting JackAsser
Remove LOADADDR and HEADER alltogether firstly if you wanna make a .crt-file.


Yes, thanks that helps.

At the beginning of the cart is bunch of NOPS, some init code and JMP * as a pause..

JMP *
.C:801e 4C 15 80 JMP $8015
it should be:
.C:801e 4C 15 80 JMP $801e

Why is it out of sync?

Disassembly of the cart start:
(C:$ff4b) d $8000
.C:8000  09 80       ORA #$80
.C:8002  09 80       ORA #$80
.C:8004  C3 C2       DCP ($C2,X)
.C:8006  CD 38 30    CMP $3038
.C:8009  EA          NOP
.C:800a  EA          NOP
.C:800b  EA          NOP
.C:800c  EA          NOP
.C:800d  EA          NOP
.C:800e  A9 1A       LDA #$1A
.C:8010  20 D2 FF    JSR $FFD2
.C:8013  A9 01       LDA #$01
.C:8015  8D 20 D0    STA $D020
.C:8018  8D 21 D0    STA $D021
.C:801b  EE 21 D0    INC $D021
.C:801e  4C 15 80    JMP $8015
.C:8021  20 90 9B    JSR $9B90
.C:8024  20 1D 8B    JSR $8B1D
.C:8027  08          PHP
.C:8028  A9 24       LDA #$24
...


I've adjusted the cfg to look like this:


FEATURES {}
SYMBOLS {
    __STACKSIZE__: type = weak, value = $0800; # 2k stack
    __HIMEM__:     type = weak, value = $8000-300;
}
MEMORY {
    ZP:       file = "", define = yes, start = $0002,           size = $001A;
    MAIN:     file = %O, define = yes, start = $8000, size=$4000;
    TEMP:       file ="", define=yes, start=$4000, size = $1000;
    BSS:      file = "",               start = __ONCE_RUN__,    size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
}
SEGMENTS {
    ZEROPAGE: load = ZP,       type = zp;
    STARTUP:  load = MAIN,     type = ro;
    LOWCODE:  load = MAIN,     type = ro,  optional = yes;
    CODE:     load = MAIN,     type = ro;
    RODATA:   load = MAIN,     type = ro;
    DATA:     load = TEMP,     type = rw;
    INIT:     load = MAIN,     type = rw;
    ONCE:     load = MAIN,     type = ro,  define   = yes;
    BSS:      load = BSS,      type = bss, define   = yes;
}
2017-01-20 00:18
wbochar

Registered: May 2002
Posts: 26
Maybe this might help:
MAIN: file = %O, define = yes, start = $8009, size=$4000;
2017-01-20 07:39
JackAsser

Registered: Jun 2002
Posts: 1987
Obviously something is inserting bytes at the beginning of the binary. The JMP $8015 is correct if that header wouldn't be there. Check the rest of the build system. Something is injecting some kind of startup there. It's not a coincidence that the first two words points at your start $8009. It's not a normal BASIC startup though. It's something else. Some kind of file header.
2017-01-21 23:16
Stone

Registered: Oct 2006
Posts: 168
The header is the standandard cartridge header. At startup, the KERNAL looks for the CBM80 header at $8004 and then does a JMP ($8000)

From that last cfg, it doesn't look like it is coming from the linker, since only MAIN is written to the output file. Is there an additional build step that is adding the header? If that is the case, setting the address of MAIN to $8009 should work.

EDIT: Also, calling $ffd2 at that point won't work, since the system has not been initialized yet. At least not from a cold start.
2017-01-22 02:14
TWW

Registered: Jul 2009
Posts: 541
Too many I's

No problem to invoke an .crt image from Kickass. I'm sure I presented the framework somewhere in the furum. If not
drop me a PM.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
iceout/Avatar/HF
Mason/Unicess
t0m3000/ibex-crew
Clown
Herrera64
Mibri/ATL^MSL^PRX
Guests online: 97
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.063 sec.