Author Topic: large clock display...  (Read 696 times)

0 Members and 1 Guest are viewing this topic.

stiggity

  • Guest
large clock display...
« on: July 08, 2012, 09:37 AM »
Greetings:
I have a small bit of code that displays the cia's (set time) to the 64's screen, and it looks pretty cool. I actually hoarked it from C-Net 64 BBS v12, and altho it works... theres alot of it i dont understand. My Question is, how can i get this to work on the 128's VDC screen. On the 64, a simple STA puts crucial pieces on the screen untill its all visible. I have had some great assistance from this forum, and i hope someone can understand my source code. But here goes, can anyone decypher this 64 code, and make it work on the 128?
 
Code: [Select]

 
*= $c000
 
COLOR = 5   ; GREEN
 
 LDA $DC0B  ; HOURS
 JSR C0DA
 PHA
 TXA
 AND #$0F
 TAX
 LDY #$0B
 JSR C049
 PLA
 AND #$01
 TAX
 LDY #$04
 JSR C049
 
 LDA $DC0A  ; MINS
 JSR C0DA
 PHA
 TXA
 AND #$0F
 TAX
 LDY #$1D
 JSR C049
 PLA
 AND #$0F
 TAX
 LDY #$16
 JSR C049
 
 LDA $DC09  ; SECS
 LSR
 LDA #$40
 ROR
 LDX #COLOR
 STA $05CC
 STX $05CC+$D400 ; STORE COLOR
 STA $0644
 STX $0644+$D400
 LDA $DC08  ; TENTHS TO START CLOCK
 RTS
 
C049 STY C0F8
 ASL
 ASL
 ASL
 TAX
 LDA #$90  ; SCREEN LOCATION
 STA $8B
 STA $8E
 LDA #$05  ; SCREEN LOCATION
 STA $8C
 LDA #$D9
 STA $8F
C058 LDA CHARSET,X
 LDY #$07
 STY C0FA
 LDY C0F8
 ASL
 STA C0F9
a1 ASL  C0F9
 LDA #$40
 ROR
 STA ($8B),Y
 LDA #COLOR  ; MAKE IT GREEN
 STA ($8E),Y
 INY
 DEC C0FA
 BNE a1
 INX
 LDA $8E
 CLC
 ADC #$28
 STA $8E
 LDA $8F
 ADC #$00
 STA $8F
 
 LDA $8B
 CLC
 ADC #$28
 STA $8B
 LDA $8C
 ADC #$00
 STA $8C
 LDA $8B
 CMP #$A8
 BNE C058
 RTS
 
C0DA PHA
 LSR
 LSR
 LSR
 LSR
 ORA #$30
 STA C0F6
 TAY
 STA C0F6
 PLA
 AND #$0F
 ORA #$30
 STA C0F7
 TAX
 STA C0F7
 TYA
 RTS
 
C0F6 .BYTE 0
C0F7 .BYTE 0
C0F8 .BYTE 0
C0F9 .BYTE 0
C0FA .BYTE 0
CHARSET .BYTE $1C,$22,$22,$22,$22,$22,$1C,$00
 .BYTE $08,$18,$08,$08,$08,$08,$1C,$00
 .BYTE $1C,$22,$02,$1C,$20,$20,$3E,$00
 .BYTE $1C,$22,$02,$0C,$02,$22,$1C,$00
 .BYTE $24,$24,$24,$3E,$04,$04,$04,$00
 .BYTE $3E,$20,$20,$3C,$02,$02,$3C,$00
 .BYTE $1C,$22,$20,$3C,$22,$22,$1C,$00
 .BYTE $3E,$02,$02,$04,$08,$10,$10,$00
 .BYTE $1C,$22,$22,$1C,$22,$22,$1C,$00
 .BYTE $1C,$22,$22,$1E,$02,$22,$1C,$00

I know its not all labeled, but its sort of hard labeling code, i found in a monitor. :)
 
-Steve
 

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #1 on: July 08, 2012, 07:26 PM »
It would be helpful if you could attach a PRG file so people could experiment / test / modify that.  I'm not going to type all that in.
 
Looking at it, it seems to do standard BCD conversion of the CIA regs into ASCII (not very effeciently however) and then use that value as a look-up into the charset table.  Based on the charset table and value in the Y register hard-coded in program it pokes both screen memory and color memory.
 
For C128, the first thing you should do is relocate it below ROM.  For example if you have it saved on disk, then in the MONITOR you can issue
Code: [Select]
L"FILENAME",8,1300
to relocate it from $c000 to $1300 (and of course the 8 is the disk device and 'filename' should be obvious).  Next use the D command to disassemble starting at $1300 and replace any reference to $c0xx to $13xx and hit RETURN to update the code.  Should only take a minute or so.
 
It also uses some zero-page addresses, $8b~8f.  Fortunately these are not critical to BASIC or the KERNAL on the C128, so you shouldn't need to change them.
 
Once you've done that, you can test it in the MONITOR with
Code: [Select]
J F1300
This will call the (relocated) code at $1300.  Note the F before the 1300 is critical.  This tells the monitor to call the routine in BANK 15 (so it can access the CIA and color RAM).  From BASIC you would use BANK 15:SYS 4864.
 
Well that would get it working in 40-column.  Be sure that is working before doing anything else.  When you are satisified it is working, be sure and save it!
Code: [Select]
S"NEWNAME",8,1300,1460
the $1460 is my rough guess of the end address after relocation.
 
Assuming you get that far, you would next need to write a pair of subroutines.  Unless you want to totally re-write it, the easiest place to put it would be after the table... around $1460.
 
Replace the code that reads
Code: [Select]
STA ($8B),Y
LDA #COLOR  ; MAKE IT GREEN
STA ($8E),Y
with
Code: [Select]
JSR $1460
NOP
NOP
NOP
The NOPs make the modified code 6 bytes long, the same as the code it replaces.
 
The $1460 might be called VDCtext... or whatever you like.  The important thing is that it saves the X and Y registers before it goes to work and restores them before returning.
 
The VDCtext ($1460) routine would need to modify the address at $8b to point to the correct screen location in VDC memory.  Basically you just remove the $400 offset of the VIC-II screen and then multiply by two.
 
You could do a similar math of the color address at $8e, but it would be much easier to simply add $800 to the address you calculated in step 1.
 
Oh yeah, before doing any math save the A register which has the character code.  Anyway, once you have the first address, restore the A register and call subroutine 2 (umm, VDCmemWrite ?).  Then calculate the color address, load A with your favorite VDC color, and call subroutine 2 again.  Finally restore the X and Y registers and RTS!
 
Subroutine 2 would go after Subroutine 1 (I'm guessing something like $14c0).  An easy way to implement it is
Code: [Select]
JMP $CDE6
I hope that is simple enough!  It just requires the address you calculated is stored in zero page address $e0.  This may interfere with normal VDC text display (not tested).  But if it does, just disassemble the Editor ROM at $CDE6 and copy the short routine there into your code but change it to use a different zero-page address.
 
I know I'm working backwards here, but to wrap things up, Subroutine 1 would be something like....
Code: [Select]
STX $145E ;save X
STY $145F ;save Y
PHA ;save char
LDA $8D ;text address low
STA $E0 ;prepare to modify
LDA $8E ;text address high
AND #3 ;remove VIC-II start
ASL $E0 ;double address low (modify)
ROL ;double address high (modify)
STA $E1
PLA ;char
JSR $14C0 ;write to VDC text
LDA $E1 ;text address high
ORA #8 ;change address for color
STA $E1
LDA #color
JSR $14C0 ;write VDC attribute
LDX $145E ;restore X
LDY $145F ;restore Y
RTS

Because the Y register is unchanged in the example code, it does not really need to be saved.  But in case you need to modify the example and use the Y register, the example will restore it.
 
Well I think that should work.  I guess you'll have to try it and see.  Good luck!
 
Oh, almost forgot, BDD wrote an interesting clock/calendar program for the VDC.  He talks about it quite a bit, and has some code snips, but unfortunately the full source is not available.  Anyway, check that out if you haven't already.
I'm kupo for kupo nuts!

Offline wte

  • C64 user
  • *****
  • Posts: 344
  • Location: Frankfurt
  • Activity:
    0.4%
  • Country: de
  • Reputation: 10
  • Gender: Male
  • With us since: 18/03/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • http://blog.c128.net
Re: large clock display...
« Reply #2 on: July 08, 2012, 07:51 PM »
Good reply by Hydrophilic, so all has been said ...

But this (red) makes no sense for me:

C0DA PHA
 LSR
 LSR
 LSR
 LSR
 ORA #$30
 STA C0F6
 TAY
 STA C0F6
  PLA
 AND #$0F
 ORA #$30
 
STA C0F7
 TAX
 STA C0F7
 
TYA
 RTS

Is the original code really ok?

I've copied the code to an editor, used the TASS cross compiler and tried the code in VICE. All I got is "01 00" (always the same time).
« Last Edit: July 08, 2012, 07:59 PM by wte »

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #3 on: July 08, 2012, 08:09 PM »
When I said the BCD conversion is not very effecient, that is what I was talking about!  It stores the same value twice and needlessly copies A to the X and Y registers.  Thanks for the attachments, I'll give it a try...
 
Edit
Tested and one problem is a typo in the original post...
Code: [Select]
LDA $DC08  ; TENTHS TO START CLOCK
should be
Code: [Select]
LDA $DC0B
Notice the correct register is #11 (hex $B) and not #8 (hex $8).  It just so happens that register #8 is the HOURS register and reading that will 'freeze' the clock.
 
However, fixing that mistake doesn't solve another problem... on the C128 the TOD is never initialized so it is initially stopped.  You need to write a value (include TENTHs register #11) to start it.
 
Well I did that and it is still not working in VICE.  I'm stumped... I need test it on my real C128 but somebody is watching television right now...
« Last Edit: July 08, 2012, 08:44 PM by Hydrophilic »
I'm kupo for kupo nuts!

stiggity

  • Guest
Re: large clock display...
« Reply #4 on: July 09, 2012, 12:43 AM »
hydro:
thanks for the break-down. I have been trying this for a few days, and im still stumped..
it works fine on the c64. I'm just having trouible getting the characters to line-up using
the $cdca call. If you can get this one working, your status as an ML-God, will be true. :)
 
--Steve
 

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #5 on: July 09, 2012, 03:44 AM »
Yeh, I got it working on my C128 once my TV was free.  I knew I had to start the CIA timer, but I was thinking the TOD registers were human-readable, like BCD, but they are reversed, low-byte first like most non-VDC registers.  So yeah, register 8 is Tenths and and 11 is hours.  Silly me!
 
Wagner, that's very well-formated code, but what is
Code: [Select]
   ldx $fffd
   cpx #$ff
   bne +
   inx
   stx $ff00
???
 
If $fffd is $FF then store zero into MMU configuration !?  Store zero is good for proper memory configuation, but only if $fffd is randomly $FF ?  Well I guess it would be $FF if standard ROM is present (for example bank 15) but in that case you wouldn't need to store zero.  And if it is not $FF then don't set correct bank? 
 
Well trying to find the change relative to the 'source' posted by WTE, the only real difference I see is that mystery MMU code and a store to Tenths to kick-start the TOD as mentioned above...
 
You did say your change is to make it run on both 64 and 128, so I guess that mystery code is designed to not change $ff00 on a c64?
 
Did you make any other changes I am missing?

Anyway, back to stiggity.  To get it working, I had to make a few changes different what I posted before.  One was simply to change the address of the subroutines because the 'original' doesn't use as much memory as I guessed.  Subroutine 1 at $1440 and Subroutine 2 at $1470.
 
Another more serious issue was the routine at $cde6 only sets the VDC RAM address, but does not actually write A into VDC RAM!  So change Subroutine 2 to be
Code: [Select]
PHA ;save char (or color)
JMP $CC54 ;call $cde6 and then $cdca

Another bug was that address to read before modify should be $8b/8c and not $8d/8e.  So Subroutine 1 becomes
Code: [Select]
STX $143E ;save X
STY $143F ;save Y
PHA ;save char
LDA $8B ;text address low <-- fixed
STA $E0 ;prepare to modify
LDA $8C ;text address high <-- fixed
AND #3 ;remove VIC-II start
ASL $E0 ;double address low (modify)
ROL ;double address high (modify)
STA $E1
PLA ;char
JSR $1470 ;write to VDC text
LDA $E1 ;text address high
ORA #8 ;change address for color
STA $E1
LDA #color
JSR $1470 ;write VDC attribute
LDX $143E ;restore X
LDY $143F ;restore Y
RTS

The final tweak was to eliminate the writing to VIC-II screen for the flashing dots.  Change 'original' from
Code: [Select]
STA $5CC
STA $D9CC
STA $644
STA $DA44
to
Code: [Select]
BIT $5CC
BIT $D9CC
BIT $644
BIT $DA44

Note those flashing colons are hard-coded and do not use the character-printing subroutine like the numbers.  If you really want the flashing colons, calculate the address and call subroutine 1.  Actually you don't need to calculate!  They are printed right above!  So for the top colon, do something like
Code: [Select]
LDX #5 ;high
LDY #$CC  ;low
STY $8B
STX $8C
LDY #0 ;no column offset
JSR $1440
and repeat for bottom colon but use address $644 instead of $5cc.
 
If you don't like the position on-screen, you can change the horizontal position easily by modify subroutine 2: every INY will move the characters to the right.  To change the vertical position (row), you will have to modify the hard-coded address(s) used in the original program.
 
Anyway, attached is working prg.  Remember the TOD will be stopped unless you program a time before running the program.
 
Also it seems that call to Editor ROM and use of zero-page $e0/e1 does not interfere with the text-screen editor (neither cursor position nor color seems affected).
« Last Edit: July 09, 2012, 03:53 AM by Hydrophilic »
I'm kupo for kupo nuts!

stiggity

  • Guest
Re: large clock display...
« Reply #6 on: July 09, 2012, 05:44 AM »
hydro:
Could you post your source?? I thought i was an Okay 128 programmer, untill i tried getting this
to work for the 100th time.... i downloaded yer .prg, but u lost me when you were referring to
subroutine # 1, #2, etc. Plus i plan on using this routine @ $B000 , just seeing yer source, i will
be able to _move it around_. you ROCk, dude...
 
--Steve
 

Offline Wagner

  • KIM-1 user
  • **
  • Posts: 13
  • Location: Minnesota
  • Activity:
    0.2%
  • Country: us
  • Reputation: 2
  • Gender: Male
  • With us since: 04/12/2011
    YearsYears
    • View Profile
Re: large clock display...
« Reply #7 on: July 09, 2012, 08:31 AM »
Quote
Wagner, that's very well-formated code, but what is
Code: [Select]

   ldx $fffd
   cpx #$ff
   bne +
   inx
   stx $ff00

???
 
If $fffd is $FF then store zero into MMU configuration !?  Store zero is good for proper memory configuation, but only if $fffd is randomly $FF ?  Well I guess it would be $FF if standard ROM is present (for example bank 15) but in that case you wouldn't need to store zero.  And if it is not $FF then don't set correct bank? 

It just means that if we're on a 128, then make sure I/O is visible.  It was a test that I borrowed from CMD's FCOPY utility.

Deleted my post because my code was only for 40 columns.
He can compress the most words into the smallest ideas of any man I ever met.

stiggity

  • Guest
Re: large clock display...
« Reply #8 on: July 09, 2012, 12:23 PM »
Hydro:
I added and changed what you mentioned, but when i do my sys4864 i get a blotch of green overtop of my "sys4864"
and thats it... tried all evening.. should i post what i have, or would you mind posting _your_ source?
 
-Steve
 

stiggity

  • Guest
Re: large clock display...
« Reply #9 on: July 09, 2012, 02:18 PM »
i got it working... ehehheh Now it looks like you were _very_ thorough Hydro.
I had a $bc instead of $8c..gotter flowin now.
 
Thank You.
-Steve
 

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #10 on: July 09, 2012, 10:35 PM »
Stiggity, glad you got it working, because I don't have any source code!  I just added the routines that I talked about using MONITOR from the .prg that WTE posted.  Wagner's source code looked pretty nice, so I hope you got it while it lasted.
 
Wagner, even though it was only 40 columns, I think it was a good job even if I wasn't sure about the MMU write...  other people would probably appreciate it too.
 
Anyway, have fun getting the clock positioned where you like it.
 
Oh, can I ask a question?  How are you running program from $b000?  With custom MMU config for KERNAL+I/O+no_BASIC... or perhaps in Bank 0 with cross-bank routines?
I'm kupo for kupo nuts!

stiggity

  • Guest
Re: large clock display...
« Reply #11 on: July 10, 2012, 01:16 AM »
Hydro:
Yes, bank 0 with cross banks. And toying with the MMU..
 

Offline millennium128

  • KIM-1 user
  • **
  • Posts: 15
  • Activity:
    0%
  • Country: us
  • Reputation: 0
  • With us since: 13/07/2012
    Years
    • View Profile
Re: large clock display...
« Reply #12 on: July 13, 2012, 12:12 PM »
hydro.. i cannot seem to be able to get the flashing colons to work.. i got the time set
and the clock is working, it's just not flashing the colons.. any advice?? :)


Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #13 on: July 14, 2012, 03:42 AM »
The file uploaded did not include support for the colons.  Have you tried this change?
... for the flashing dots.  Change 'original' from
Code: [Select]
STA $5CC
STA $D9CC
STA $644
STA $DA44
to
Code: [Select]
BIT $5CC
BIT $D9CC
BIT $644
BIT $DA44

Note those flashing colons are hard-coded and do not use the character-printing subroutine like the numbers.  If you really want the flashing colons, calculate the address and call subroutine 1.  Actually you don't need to calculate!  They are printed right above!  So for the top colon, do something like
Code: [Select]
LDX #5 ;high
LDY #$CC  ;low
STY $8B
STX $8C
LDY #0 ;no column offset
JSR $1440
and repeat for bottom colon but use address $644 instead of $5cc.
If you tried that but it doesn't work, attach a .prg file or source code and I'll take a look to see what might be the problem.
I'm kupo for kupo nuts!

Offline millennium128

  • KIM-1 user
  • **
  • Posts: 15
  • Activity:
    0%
  • Country: us
  • Reputation: 0
  • With us since: 13/07/2012
    Years
    • View Profile
Re: large clock display...
« Reply #14 on: July 15, 2012, 06:08 AM »
Hydro:
I have tried that, but only get the upper colon to come onto the screen, and the lower is a capital "E". Here is where i may be screwing up, where in my original source code, do i put your routine(s)?


this has been added.

BIT $5CC
BIT $D9CC
BIT $644
BIT $DA44

but where in the code, should i put this..

LDX #5 ;high
LDY #$CC  ;low
STY $8B
STX $8C
LDY #0 ;no column offset
JSR $1440

then for the bottom colon..

ldx#$05
ldy #$cc
sty $8b
stx $8c
ldy #$00
jsr $1440

my clock works great, and ive even spaced it to theright farther, so i guess, once i get the colons working, im going to have to space
themselves over also?

-Steve

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: large clock display...
« Reply #15 on: July 16, 2012, 10:21 AM »
The BIT commands were just a hack to the original because it was STA to VIC screen.  You don't need it, you can remove it.
 
In the original, find those 4 STA/STX commands... that is where you should put the new code.  But you can't because it won't fit (unless you re-write it all).  In other words, if you are using an assembler you can easily delete those 4 STA commands and insert the new code.  But if you are just hacking the original with MONITOR, then you need to JSR to a patch routine.
 
For example,
Code: [Select]
.133B STA $5CC
.133E STX $D9CC
.1341 STA $644
.1344 STX $DA44

change to
 
Code: [Select]
.133B BIT $5CC
.133E BIT $D9CC
.1341 BIT $644
.1344 JSR $1480

$1480 would be a good place to put the patch.  You were getting garbage for 2nd colon because the .A register (character) was changed by the printing routine.  An easy fix is to use PHA / PLA.
 
Code: [Select]
LDX #5 ;high
LDY #$CC  ;low
STY $8B
STX $8C
LDY #0 ;no column offset
PHA ;<-- save char
JSR $1440 ;draw top colon
 
LDX #6 ;high
LDY #$44  ;low
STY $8B
STX $8C
LDY #0 ;no column offset
PLA ;<-- recall char
JSR $1440 ;draw bottom colon
RTS ; end patch

That should work.
 
Note you can save some bytes and make it a tiny bit faster if you remove the last LDY#0 (it should still be 0), and also the final JSR $1440 / RTS can be simply JMP $1440 (because it ends with an RTS)... I hope that makes sense!
 
Depending on what you changed to move the numbers, the colons may move automatically, wouldn't that be nice ?!  If not, just change the LDY #0 to another value to move them to the right however much you need.
 
Anyway, good luck!
I'm kupo for kupo nuts!

Offline millennium128

  • KIM-1 user
  • **
  • Posts: 15
  • Activity:
    0%
  • Country: us
  • Reputation: 0
  • With us since: 13/07/2012
    Years
    • View Profile
Re: large clock display...
« Reply #16 on: July 22, 2012, 11:25 PM »
Hydro:
yeah i understand jmp to fall thru a subroutine. ehehheh got the colons working.. i really appreciate the examples.

-Steve

 



Back to top