magazines:chacking1
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | magazines:chacking1 [2015-04-17 04:34] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== C= Hacking #1 ====== | ||
+ | < | ||
+ | Sorry that this is later than I had hoped to get it out, but here it is -- | ||
+ | Expect another one soon in a month or two depending on submissions... Praise, | ||
+ | Comments, (It sucks, I loved it, etc) are welcome -> | ||
+ | duck@pembvax1.pembroke.edu. | ||
+ | drawing / dot plotting with the 80 column screen on the C=128. | ||
+ | |||
+ | =============================================================================== | ||
+ | Hacking / This Magazine | ||
+ | by Craig Taylor | ||
+ | duck@pembvax1.pembroke.edu | ||
+ | |||
+ | Def: | ||
+ | Hacker - Noun - A talented amateur user of computers. | ||
+ | Source - Webster' | ||
+ | |||
+ | Correction: | ||
+ | Hacker - Noun - A talented user of computers. | ||
+ | |||
+ | |||
+ | There, now that we got that out of the way, let's see how some people | ||
+ | interpret the word hacker. In the 1980's newspapers, magazines, movies - | ||
+ | everywhere ya looked people were using the term " | ||
+ | maliciously tried to destroy / bore ill intent towards another computer system. | ||
+ | This was the result of the misunderstanding of the actual definition of | ||
+ | " | ||
+ | |||
+ | This magazine will not tell people how to " | ||
+ | mailboxes and other illegal activities. | ||
+ | some of the " | ||
+ | the Commodore 64 and Commodore 128 that are just now being revealed. | ||
+ | In the event that an article is submitted and there is a question about it's | ||
+ | ability to be applied towards illegal activites, the article will be carried | ||
+ | with a warning that the intent is not towards that activity. | ||
+ | will never come along. :-) | ||
+ | The Commodore 64 came out in late 1982 (I believe) and was known to only | ||
+ | support 16 colors, 320 x 200 resolution graphics of 2 colors, 160x200 | ||
+ | resolution graphics of 4 colors. | ||
+ | 64 to its limits with apparent resolution of 320 x 200 with a resolution of 4 | ||
+ | colors and even higher... more than 8 sprites on the screen... fast | ||
+ | high-quality digitized sounds.... | ||
+ | The Commodore 128 came out as an " | ||
+ | it's unique memory management scheme and the Z80a chip still on there people | ||
+ | are still finding out unique and interesting ways to explore the C=128. One of | ||
+ | the most interesting has been that of the seperate video display chip which | ||
+ | makes it possible to dispaly 640x200 resolution graphics quickly and easily. | ||
+ | |||
+ | **ATTENTION** | ||
+ | This magazine is going to be a sourcebook of many people - If you know | ||
+ | anything about something, please feel free to submit it. Just mail the article | ||
+ | to the following : | ||
+ | duck@pembvax1.pembroke.edu | ||
+ | and a subject of " | ||
+ | |||
+ | The source code for all programs mentioned within articles will be provided | ||
+ | as well as any executables uuencoded sent out seprately. [Ed. Note - In this | ||
+ | issue, the source is not sent seperately due to only one article with files] | ||
+ | |||
+ | In addition, the magazine will go out when there are enough articles | ||
+ | collected. | ||
+ | few tests etc being around the release period. | ||
+ | |||
+ | In this issue: | ||
+ | |||
+ | Title | ||
+ | ------------------------------------------------------------------------------ | ||
+ | Hacking - Definition Of duck@pembvax1.pembroke.edu | ||
+ | Learning ML - Part 1 duck@pembvax1.pembroke.edu | ||
+ | 6502 Known/ | ||
+ | Dot Plotting & Bitmapping csbruce@ccnga.uwaterloo.ca | ||
+ | the 8563 Screen. | ||
+ | |||
+ | ** All articles and files (C) 1992 by their respective authors. | ||
+ | ============================================================================= | ||
+ | </ | ||
+ | |||
+ | ====== Beginning ML - Part One ====== | ||
+ | < | ||
+ | (C) 1992 by Craig Taylor | ||
+ | |||
+ | The best way to learn machine language is to actually code routines that you | ||
+ | don't think will work, hope that they work, and then figure out why they don't | ||
+ | work. (If they do work, you try to figure out why you didn't think they'd | ||
+ | work). | ||
+ | THAT LANGUAGE. | ||
+ | Now, let's get a few terms and definitions out of the way: | ||
+ | |||
+ | Machine Language - Instructions that the computer understands at a primitive | ||
+ | level and executes accordingly. | ||
+ | Assembly Language - Instructions more understandable to humans than pure | ||
+ | | ||
+ | |||
+ | Assembly: | ||
+ | Example: | ||
+ | |||
+ | Huh? you might be saying at the moment. | ||
+ | a mnemonic (computer people always come up with these big long words -- you'll | ||
+ | see mnemonic' | ||
+ | "LOAD register A with the following value" | ||
+ | | ||
+ | Cool 'eh? Yeah, but there' | ||
+ | LOADA etc.. Hey, that's life. (GRIN). | ||
+ | | ||
+ | Oh, more definitions: | ||
+ | |||
+ | Register - A location inside the CPU that can be manipulated directly without | ||
+ | | ||
+ | |||
+ | The " | ||
+ | function: all math and logical manipulations are done to the " | ||
+ | hereon out it will be referred to as .A). | ||
+ | There are two other registers inside the 6502 processor, specifically .X and | ||
+ | .Y. These registers help act as counters and indexes into memory (sorta like | ||
+ | mem[x] in pascal but not quite...). | ||
+ | |||
+ | Now, let's add 3 and 5 and leave the result in the accumalator (.A). | ||
+ | |||
+ | lda #3 ; Here .A = 3 (anything w/ a ; is a | ||
+ | ; comment and will be ignored by the assembler... | ||
+ | clc ; hu? - This clears the carry. The 6502 | ||
+ | ; does addition *everytime* with the carry ... so if we clear it it won't | ||
+ | ; affect the result. | ||
+ | adc #5 ; Now, .A = .A + 5 | ||
+ | |||
+ | and we're done. If the CLC confused you then consider that if you're adding | ||
+ | a column of #'s: | ||
+ | |||
+ | 12 < | ||
+ | + 89 < | ||
+ | -- | ||
+ | 101 | ||
+ | Then we say 1 + 8 + carry , which in this case happens to = 1 and we get 10 | ||
+ | and again we set the carry and write down 0. Then it's just the carry and we | ||
+ | write that down. If we didn't clear the carry we may have ended up with the | ||
+ | value of 9 instead 8 if the carry had happened to be set. | ||
+ | | ||
+ | Aaagh, Math - Let's continue - The CLC mnemonic stands for "CLEAR CARRY" and | ||
+ | the ADC stands for "ADD with CARRY" | ||
+ | (without a carry) but unfortunately the 6502 processor inside the C=64 doesn' | ||
+ | have it. | ||
+ | So we've got: | ||
+ | load reg A with the value 5 lda #5 | ||
+ | clear the carry clc | ||
+ | add reg a and value 3 adc #3 | ||
+ | |||
+ | In Basic it's just: | ||
+ | A = 5+3 | ||
+ | |||
+ | One statement... In Machine Language you've got to break everything down into | ||
+ | smaller and smaller steps and quite often the ML listing will be far longer | ||
+ | than the BASIC or PASCAL or C equivlent. | ||
+ | |||
+ | | ||
+ | | ||
+ | writes to memory or a file the resulting executable. Allows higher flexibility | ||
+ | than a monitor (see below) due to use of labels etc and not having to keep | ||
+ | track of each address within the program. | ||
+ | |||
+ | Monitor - A program, resident in memory, invoked by a sys call from basic or | ||
+ | by hitting the restore key that will let you disassemble, | ||
+ | areas of memory and execute programs directly from the monitor. Useful for | ||
+ | debugging programs and for writing short programs. | ||
+ | | ||
+ | Let's enter the following into a monitor (if you don't have one then contact | ||
+ | duck@pembvax1.pembroke.edu and I'll send ya one): | ||
+ | |||
+ | 128: c64: | ||
+ | >a 1300 lda #$93 | ||
+ | >a 1302 jsr $ffd2 >a c003 jsr $ffd2 | ||
+ | >a 1305 rts >a c005 rts | ||
+ | (exit monitor) (exit monitor) | ||
+ | bank15: | ||
+ | |||
+ | Wow! It cleared the screen. Neat ' | ||
+ | problems down? The first statement loads in $93 hex into the accumalator ($93 | ||
+ | hex just happens to equal 147 which is also the Commodorscii code for clear | ||
+ | screen. | ||
+ | computer). | ||
+ | supplied us with that prints the value of the character in .A to the screen. | ||
+ | (jsr $ffd2) then we do a RTS (ReTurn from Subroutine) so that we will go back | ||
+ | to basic and the Ready prompt when we are finished with the sys call. | ||
+ | You C= 128 people may be wondering why you had to do a bank 15 and assemble | ||
+ | the stuff at a different memory location. | ||
+ | of where routines etc are at is much more complex than the C=64 and thus you | ||
+ | have to tell basic which bank you wish to have all sys, peek, and poke calls to | ||
+ | take place in. Also, $c000 as used on the C=64 is not an area that is free to | ||
+ | use on the C128 in this manner. | ||
+ | |||
+ | Assignment: Take a look @ the different commands as listed in 6502 Opcodes | ||
+ | and try to understand what they do. Experiment with the jsr $ffd2 routine by | ||
+ | using different values etc. | ||
+ | |||
+ | Next Time: Printing out strings, and understanding ' | ||
+ | |||
+ | =========================================================================== | ||
+ | </ | ||
+ | |||
+ | ====== 6502 Opcodes and Quasi-Opcodes ====== | ||
+ | < | ||
+ | |||
+ | The following table lists all of the available opcodes on the 65xx line of | ||
+ | micro-processors (such as the 6510 on the C=64 and the 8502 on the C=128) | ||
+ | |||
+ | ----------------------------------------------------------------------------- | ||
+ | Std Mnemonic Hex Value Description | ||
+ | * | ||
+ | * | ||
+ | JAM $02 | ||
+ | SLO $03 M <- (M >> 1) + A + C (Ind, | ||
+ | NOP $04 [no operation] | ||
+ | * | ||
+ | * | ||
+ | SLO $07 M <- (M >> 1) + A + C (Z-Page) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ANC $0B A <- A /\ M, C=~A7 | ||
+ | NOP $0C [no operation] | ||
+ | * | ||
+ | * | ||
+ | SLO $0F M <- (M >> 1) + A + C (Absolute) | ||
+ | * | ||
+ | * | ||
+ | JAM $12 | ||
+ | SLO $13 M <- (M >. 1) + A + C ((Ind), | ||
+ | NOP $14 [no operation] | ||
+ | * | ||
+ | * | ||
+ | SLO $17 M <- (M >> 1) + A + C (Z-Page, | ||
+ | * | ||
+ | * | ||
+ | NOP $1A [no operation] | ||
+ | SLO $1B M <- (M >> 1) + A + C (Absolute, | ||
+ | NOP $1C [no operation] | ||
+ | * | ||
+ | * | ||
+ | SLO $1F M <- (M >> 1) + A + C (Absolute, | ||
+ | * | ||
+ | * | ||
+ | JAM $22 | ||
+ | RLA $23 M <- (M << 1) /\ (A) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | RLA $27 M <- (M << 1) /\ (A) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ANC $2B A <- A /\ M, C <- ~A7 (Immediate9 | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | RLA $2F M <- (M << 1) /\ (A) | ||
+ | * | ||
+ | * | ||
+ | JAM $32 | ||
+ | RLA $33 M <- (M << 1) /\ (A) | ||
+ | NOP $34 [no operation] | ||
+ | * | ||
+ | * | ||
+ | RLA $37 M <- (M << 1) /\ (A) | ||
+ | * | ||
+ | * | ||
+ | NOP $3A [no operation] | ||
+ | RLA $3B M <- (M << 1) /\ (A) | ||
+ | NOP $3C [no operation] | ||
+ | * | ||
+ | * | ||
+ | RLA $3F M <- (M << 1) /\ (A) | ||
+ | * | ||
+ | * | ||
+ | JAM $42 | ||
+ | SRE $43 M <- (M >> 1) \-/ A (Ind, | ||
+ | NOP $44 [no operation] | ||
+ | * | ||
+ | * | ||
+ | SRE $47 M <- (M >> 1) \-/ A (Z-Page) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ASR $4B A <- [(A /\ M) >> 1] | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SRE $4F M <- (M >> 1) \-/ A (Absolute) | ||
+ | * | ||
+ | * | ||
+ | JAM $52 | ||
+ | SRE $53 M <- (M >> 1) \-/ A ((Ind), | ||
+ | NOP $54 [no operation] | ||
+ | * | ||
+ | * | ||
+ | SRE $57 M <- (M >> 1) \-/ A (Z-Page, | ||
+ | * | ||
+ | * | ||
+ | NOP $5A [no operation] | ||
+ | SRE $5B M <- (M >> 1) \-/ A (Absolute, | ||
+ | NOP $5C [no operation] | ||
+ | * | ||
+ | SRE $5F M <- (M >> 1) \-/ A (Absolute, | ||
+ | * | ||
+ | * | ||
+ | JAM $62 | ||
+ | RRA $63 M <- (M >> 1) + (A) + C (Ind, | ||
+ | NOP $64 [no operation] | ||
+ | * | ||
+ | * | ||
+ | RRA $67 M <- (M >> 1) + (A) + C (Z-Page) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ARR $6B A <- [(A /\ M) >> 1] | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | RRA $6F M <- (M >> 1) + (A) + C (Absolute) | ||
+ | * | ||
+ | * | ||
+ | JAM $72 | ||
+ | RRA $73 M <- (M >> 1) + (A) + C ((Ind), | ||
+ | NOP $74 [no operation] | ||
+ | * | ||
+ | * | ||
+ | RRA $77 M <- (M >> 1) + (A) + C (Z-Page, | ||
+ | * | ||
+ | * | ||
+ | NOP $7A [no operation] | ||
+ | RRA $7B M <- (M >> 1) + (A) + C (Absolute, | ||
+ | NOP $7C [no operation] | ||
+ | * | ||
+ | * | ||
+ | RRA $7F M <- (M >> 1) + (A) + C (Absolute, | ||
+ | NOP $80 [no operation] | ||
+ | * | ||
+ | NOP $82 [no operation] | ||
+ | SAX $83 M <- (A) /\ (X) (Ind, | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SAX $87 M <- (A) /\ (X) (Z-Page) | ||
+ | * | ||
+ | NOP $89 [no operation] | ||
+ | * | ||
+ | ANE $8B M < | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SAX $8F M <- (A) /\ (X) (Absolute) | ||
+ | * | ||
+ | * | ||
+ | JAM $92 | ||
+ | SHA $93 M <- (A) /\ (X) /\ (PCH+1) (Absolute, | ||
+ | * | ||
+ | * | ||
+ | SAX $97 M <- (A) /\ (X) (Z-Page, | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SHS $9B X <- (A) /\ (X), S <- (X) (Absolute, | ||
+ | M <- (X) /\ (PCH+1) | ||
+ | SHY $9C M <- (Y) /\ (PCH+1) | ||
+ | * | ||
+ | SHX $9E M <- (X) /\ (PCH+1) | ||
+ | SHA $9F M <- (A) /\ (X) /\ (PCH+1) (Absolute, | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAX $A3 A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAX $A7 A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LXA $AB X04 <- (X04) /\ M04 (Immediate) | ||
+ | A04 <- (A04) /\ M04 | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAX $AF A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | JAM $B2 | ||
+ | LAX $B3 A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAX $B7 A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAE $BB X,S,A <- (S /\ M) (Absolute, | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | LAX $BF A <- M, X <- M | ||
+ | * | ||
+ | * | ||
+ | NOP $C2 [no operation] | ||
+ | DCP $C3 M <- (M)-1, (A-M) -> NZC | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | DCP $C7 M <- (M)-1, (A-M) -> NZC | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SBX $CB X <- (X)/\(A) - M (Immediate) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | DCP $CF M <- (M)-1, (A-M) -> NZC | ||
+ | * | ||
+ | * | ||
+ | JAM $D2 | ||
+ | DCP $D3 M <- (M)-1, (A-M) -> NZC | ||
+ | NOP $D4 [no operation] | ||
+ | * | ||
+ | * | ||
+ | DCP $D7 M <- (M)-1, (A-M) -> NZC | ||
+ | * | ||
+ | * | ||
+ | NOP $DA [no operation] | ||
+ | DCP $DB M <- (M)-1, (A-M) -> NZC | ||
+ | NOP $DC [no operation] | ||
+ | * | ||
+ | * | ||
+ | DCP $DF M <- (M)-1, (A-M) -> NZC | ||
+ | * | ||
+ | * | ||
+ | NOP $E2 [no operation] | ||
+ | ISB $E3 M <- (M) - 1,A <- (A)-M-~C (Ind, | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ISB $E7 M <- (M) - 1,A <- (A)-M-~C (Z-Page) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | SBC $EB A <- (A) - M - ~C (Immediate) | ||
+ | * | ||
+ | * | ||
+ | * | ||
+ | ISB $EF M <- (M) - 1,A <- (A)-M-~C (Absolute) | ||
+ | * | ||
+ | * | ||
+ | JAM $F2 | ||
+ | ISB $F3 M <- (M) - 1,A <- (A)-M-~C ((Ind), | ||
+ | NOP $F4 [no operation] | ||
+ | * | ||
+ | * | ||
+ | ISB $F7 M <- (M) - 1,A <- (A)-M-~C (Z-Page, | ||
+ | * | ||
+ | * | ||
+ | NOP $FA [no operation] | ||
+ | ISB $FB M <- (M) - 1,A <- (A)-M-~C (Absolute, | ||
+ | NOP $FC [no operation] | ||
+ | * | ||
+ | * | ||
+ | ISB $FF M <- (M) - 1,A <- (A)-M-~C (Absolute, | ||
+ | |||
+ | '1 - Add one if address crosses a page boundry. | ||
+ | '2 - Add 1 if branch succeeds, or 2 if into another page. | ||
+ | '3 - If page boundry crossed then PCH+1 is just PCH | ||
+ | '4 - Sources disputed on exact operation, or sometimes does not work. | ||
+ | '5 - Full eight bit rotation (with carry) | ||
+ | |||
+ | Sources: | ||
+ | Programming the 6502, Rodney Zaks, (c) 1983 Sybex | ||
+ | Paul Ojala, Post to Comp.Sys.Cbm (po87553@cs.tut.fi / albert@cc.tut.fi) | ||
+ | D John Mckenna, Post to Comp.Sys.Cbm (gudjm@uniwa.uwa.oz.au) | ||
+ | |||
+ | Compiled by Craig Taylor (duck@pembvax1.pembroke.edu) | ||
+ | |||
+ | </ | ||
+ | ====== Simple Hires Line Drawing Package for the C-128 80-Column Screen ====== | ||
+ | < | ||
+ | Copyright (c) 1992 Craig Bruce < | ||
+ | |||
+ | 1. GRAPHICS PACKAGE OVERVIEW | ||
+ | |||
+ | The graphics package this article explains is BLOADed into memory at address | ||
+ | $1300 on bank 15 and has three entry points: | ||
+ | |||
+ | $1300 = move the pixel cursor or draw a line: .AX=x, .Y=y, .C=cmd | ||
+ | $1303 = activate graphics mode and clear the screen | ||
+ | $1306 = exit graphics mode and reload the character set | ||
+ | |||
+ | To move the pixel cursor to the start point of a line, load the .AX registers | ||
+ | with the X coordinate (0-639), load the .Y register with the Y coordinate | ||
+ | (0-199), clear the carry flag, and call $1300. | ||
+ | context). | ||
+ | |||
+ | SYS 4864, X AND 255, X/256, Y, 0 | ||
+ | |||
+ | To draw a line from the pixel cursor location to a given point, load the .AX | ||
+ | and .Y registers like before, set the carry flag, and call $1300. | ||
+ | cursor will then be set to the end point of the line just drawn, so you do not | ||
+ | have to set it again if you are drawing a continuous object (like a square). | ||
+ | |||
+ | SYS 4864, X AND 255, X/256, Y, 1 | ||
+ | |||
+ | The activate and exit routines are called without any parameters and work very | ||
+ | simply. | ||
+ | editing mode or you will not be able to see what you are typing. | ||
+ | |||
+ | A BASIC demonstration program is also included in the UU section for this | ||
+ | package. | ||
+ | and then picks a random point to draw to, and repeats until you press a key | ||
+ | to stop it. For an interesting effect, put a call to $1303 immediately before | ||
+ | the call to draw the line. | ||
+ | |||
+ | The point plotting speed is about 4,100 pixels per second and the line drawing | ||
+ | speed is a bit slower than this because of all of the calculations that have | ||
+ | to be done to draw a line. There are faster pixel plotting and line drawing | ||
+ | algorithms than the ones implemented here, but that is material for a future | ||
+ | article. | ||
+ | |||
+ | 2. INTRODUCTION TO THE VDC | ||
+ | |||
+ | Programming the 8563 Video Display Controller is quite straight forward. | ||
+ | access it a bit indirectly, but it can still be done at relatively high speeds | ||
+ | using machine language. | ||
+ | 64K of dedicated display memory that is separate from the main processor. | ||
+ | memory must be accessed through the VDC registers. | ||
+ | |||
+ | The important VDC registers for this exercise are: | ||
+ | |||
+ | REG | ||
+ | --- | ||
+ | $12 | ||
+ | $13 | ||
+ | $18 | ||
+ | $19 | ||
+ | $19 | ||
+ | $1a | ||
+ | $1a | ||
+ | $1e | ||
+ | $1f | ||
+ | |||
+ | You access the VDC chip registers though addresses $D600 and $D601 on bank 15. | ||
+ | Location $D600 selects the VDC register to use on write and returns the VDC | ||
+ | status on read. The only important status information is bit 7 (value $80) | ||
+ | which is the " | ||
+ | value in .A to VDC register number .X: | ||
+ | |||
+ | VdcRead: | ||
+ | WaitLoop: bit $d600 WaitLoop: bit $d600 | ||
+ | bpl WaitLoop | ||
+ | lda $d601 sta $d601 | ||
+ | rts rts | ||
+ | |||
+ | Once the current VDC register is selected at $d600, it remains selected. | ||
+ | may read or write it though $d601 as many times as you like as long as you | ||
+ | wait for the VDC to be " | ||
+ | |||
+ | In order to access the VDC RAM, you must first put the high and low bytes of | ||
+ | the VDC RAM address into registers $12 and $13 (high byte first) and then | ||
+ | read or write through register $1f to read or write the data in the VDC RAM. | ||
+ | After each access to register $1f, the VDC RAM address is incremented by one. | ||
+ | So, if you repeatedly read or write to register $1f you can read or write a | ||
+ | chunk of VDC memory very quickly. | ||
+ | |||
+ | 3. ENTERING GRAPHICS MODE | ||
+ | |||
+ | Activating the graphics mode of the VDC is very simple - you just have to set | ||
+ | bit 7 of VDC register $19 and poof! You should also clear bit 6 of that | ||
+ | register to disable the character color mode. This graphics package supports | ||
+ | only monochrome graphics since the standard 16K VDC does not have enough space | ||
+ | to hold both the bitmap and the 8*8 pixel cell attributes. | ||
+ | display takes 128,000 bits or 16,000 bytes. | ||
+ | that is not needed by the bitmap but it is not large enough to do anything | ||
+ | with, so it is wasted. | ||
+ | |||
+ | When you disable the character color mode, the VDC takes its foreground and | ||
+ | background color values from register $1a. The foreground color is what color | ||
+ | the " | ||
+ | " | ||
+ | |||
+ | Now that the bitmap mode is set up, we must clear the VDC memory locations 0 | ||
+ | to 15999 (decimal) to clear the bitmap screen. | ||
+ | using the VDC fill mode. If you poke a value into VDC register number $1e, | ||
+ | the VDC will fill its memory from the location currently in the VDC RAM | ||
+ | address registers for the number of bytes you just poked into register $1e | ||
+ | with the value that you last poked into the VDC RAM data register. | ||
+ | assuming that " | ||
+ | the repeat register it means to fill 256 bytes. | ||
+ | |||
+ | So, to clear the bitmap, poke a zero into both of the VDC RAM address | ||
+ | registers since the bitmap starts at location 0. Then poke a value of 0 into | ||
+ | VDC RAM data register. | ||
+ | RAM location. | ||
+ | register 63 times. | ||
+ | We end up filling 16,129 bytes, but that is not a problem since we have 384 | ||
+ | " | ||
+ | memory at a rate of about 1 Megabyte per second (if I remember my test results | ||
+ | correctly), so clearing the screen is a PDFQ operation. | ||
+ | |||
+ | 4. EXITING GRAPHICS MODE | ||
+ | |||
+ | To exit from graphics mode we have to reload the character set from the ROM | ||
+ | on bank 14 and we have to go back into character mode and clear the text | ||
+ | screen. | ||
+ | The only problem with it is that it is a lot slower than it has to be. It | ||
+ | takes about 0.45 seconds whereas the same job can be done in about 0.09 | ||
+ | seconds. | ||
+ | |||
+ | Then you just set the bitmap mode bit to zero and the character color mode to | ||
+ | one. This gets you back to normal character mode. You also have to clear the | ||
+ | text screen since it will be filled with garbage from the graphing. | ||
+ | |||
+ | 5. POINT PLOTTING | ||
+ | |||
+ | The pixels on the screen accessed by their X and Y coordinates, | ||
+ | 0 <= Y <= 199. The formula to calculate the byte address in the VDC RAM given | ||
+ | the X and Y coordinates is made simple by the mapping of bytes to the pixels | ||
+ | on the screen. | ||
+ | 8*8 cells like the VIC screen. | ||
+ | bytes of VDC RAM. | ||
+ | |||
+ | The formula for the byte address of a pixel is: AD=Y*80+INT(X/ | ||
+ | formula for the bit number is simply BI=X AND 7. The bit number can be used | ||
+ | as an index into a table of bit values: [$80, | ||
+ | such that index 0 contains $80, since the highest bit is the leftmost bit. | ||
+ | |||
+ | Calculating the bit number and looking up the bit value is very easy to do in | ||
+ | machine language, but the byte address calculation requires a little more | ||
+ | work. First we have to multiply the Y value by 80, using a 16-bit word for | ||
+ | storage. | ||
+ | Y value, and shifting left four more times. | ||
+ | right by three using a 16-bit word for storage to get INT(X/8), and we add the | ||
+ | two results together and we have the byte address. | ||
+ | |||
+ | To plot the point, we have to peek into the VDC RAM at the byte address to see | ||
+ | what is " | ||
+ | the " | ||
+ | address. | ||
+ | after each reference, we will have to set it twice - once for the read and | ||
+ | once for the write. | ||
+ | times for each pixel. | ||
+ | monochrome bitmap mode (it has less work to do than in color character mode, | ||
+ | so it is able to pay more attention to the CPU). | ||
+ | |||
+ | Effects other than just plotting the point can be achieved by using functions | ||
+ | other than OR to put the point on the background. | ||
+ | and AND-NOT (achieved by LDA bitval : EOR #$ff : AND background) would erase | ||
+ | the pixel. | ||
+ | |||
+ | 6. LINE DRAWING | ||
+ | |||
+ | The line drawing routine that is implemented in the package is given by the | ||
+ | following BASIC code (in fact, I programmed it in BASIC first to get it | ||
+ | working; of course, the BASIC version is as slow as hell): | ||
+ | |||
+ | 10 dx=x-lx: | ||
+ | 20 if abs(dx)> | ||
+ | 30 bend:else r=dy: | ||
+ | 40 px=lx+0.5: | ||
+ | 50 fori=1to abs(r): <PLOT PX,PY> : | ||
+ | 60 lx=x:ly=y | ||
+ | |||
+ | This implements the Basic Incremental Algorithm for raster line drawing. | ||
+ | " | ||
+ | coordinates to draw the line to. The " | ||
+ | X and Y directions. | ||
+ | a constant of 1 in one direction and by a fraction 0.0 <= g <= 1.0 in the | ||
+ | other direction. | ||
+ | |||
+ | Lines 20 and 30 figure out the increments for the X and Y directions (" | ||
+ | " | ||
+ | We check the " | ||
+ | that will be the direction that is incremented by 1, 0, or -1 and the other | ||
+ | direction will increment by the (fractional) slope of the line with respect to | ||
+ | the other direction. | ||
+ | |||
+ | Line 40 starts the plotting at the current pixel cursor location PLUS 0.5. We | ||
+ | add 1/2 to the X and Y positions to " | ||
+ | didn't do this, we would notice dis-symmetry in plotting to the left and to | ||
+ | the right. | ||
+ | truncate these values, going left by 0.3 moves us to position 49 whereas going | ||
+ | right by 0.3 makes us stay in the same position. | ||
+ | makes plots look a bit off. Adding 0.5 corrects the problem. | ||
+ | |||
+ | Line 50 goes into a loop for the longest dimension of the line (the one | ||
+ | incremented by 1). The <PLOT PX,PY> is not exactly BASIC; you substitute | ||
+ | the call to the point plot routine described in the previous section. | ||
+ | repeatedly adds the X and Y increment values until the line is finished. | ||
+ | This algorithm draws the line in the direction that your end points imply. | ||
+ | |||
+ | 6.1. FRACTIONAL NUMBER REPRESENTATION | ||
+ | |||
+ | There are only two real complications to the machine language implementation | ||
+ | are the representation of the signed fractional numbers and the division of | ||
+ | the fractional numbers. | ||
+ | a 16-bit signed integer portion (-32768 to +32767) and a 16-bit fractional | ||
+ | portion (0.0 to 0.99998474 in 0.00001526 increments). | ||
+ | the bit positions are as follows: | ||
+ | |||
+ | POS 31... 22 21 20 19 18 17 16 15 14 13 12 11 | ||
+ | VAL -32768... 64 32 16 8 4 2 1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 ...1/65536 | ||
+ | |||
+ | For example, 0...00001011101.10011010000...0 (notice the BINARY point) is | ||
+ | 64 + 16 + 8 + 4 + 1 + 1/2 + 1/16 + 1/32 + 1/128 = 93.6015625 in decimal. | ||
+ | as a short cut, you can consider the integer 16 bits and the fractional 16 | ||
+ | bits as independent words and add 1/65536th of the second to the first. | ||
+ | for the example above, the quantity is 93 + (32768+4096+2048+512)/ | ||
+ | 93.6015625. | ||
+ | whereas the second calculation uses base 65536. | ||
+ | |||
+ | Two's complement representation is used to achieve signedness (, | ||
+ | should all know about two's comp. Well, it works just fine for fractional | ||
+ | binary numbers as well. In fact, it makes no difference at all. You can just | ||
+ | think of the quantity as an integer number of 65536ths of a pixel and you get | ||
+ | the integer operations of complement, add, and subtract for free. The easy | ||
+ | way to get the two's comp. representation of a number is to take the positive | ||
+ | binary image of the number and subtract it from 0 (this makes perfect sense | ||
+ | since 0 - x = -x). | ||
+ | |||
+ | Fractional binary division is a little more complicated. | ||
+ | with the binary point, since the laws of mathematics say we can multiply the | ||
+ | top and bottom by the same quantity (like 65536) without changing the result, | ||
+ | but handling the two's complement is a problem. | ||
+ | what the sign of the result of the division was going to be (by EORing the | ||
+ | sign bits together) and then converted the two operands to their positive | ||
+ | value if they were originally negative. | ||
+ | unsigned division operation and then I convert the result to a negative if the | ||
+ | result is supposed to be negative. | ||
+ | complicated; | ||
+ | those days) except you use binary digits. | ||
+ | exactly rival supercomputer speeds, but it does get the job done. | ||
+ | |||
+ | 6.2. MACHINE LANGUAGE OPERATION | ||
+ | |||
+ | While drawing the line, the X and Y coordinates are 32-bit signed fractional | ||
+ | numbers as well as the " | ||
+ | 20 and 30 require quite a bit of work in 6502 machine language and use the | ||
+ | 32-bit add, subtract, 2's complement, and divide operations described in the | ||
+ | previous section. | ||
+ | whether it is positive or negative. | ||
+ | is negative, just do a 2's complement on it (makes sense: 0 - (-x) = x). | ||
+ | |||
+ | Line 40 is done by simply taking the pixel cursor X and Y coordinates (which | ||
+ | are stored as unsigned integers and are remembered between line draw calls) | ||
+ | and put them into the high word of a 32-bit field and then put $8000 (32768) | ||
+ | into the low word (which gives V + 1/2 (or V + 32768/ | ||
+ | |||
+ | Line 50 is easily implemented as a loop that decrements the " | ||
+ | reaches zero, while calling the point plot routine and doing the 32-bit add to | ||
+ | add the " | ||
+ | final X and Y coordinates are put back into the pixel cursor position storage | ||
+ | and the package is ready for the next call. | ||
+ | |||
+ | 7. CONCLUSION | ||
+ | |||
+ | Ha! This ain't no formal paper so I don't have to write a conclusion. | ||
+ | So there! [Ed.Note - He is currently working on his Masters thesis, so you'll | ||
+ | have to pardon 'im here.. (grin) ] | ||
+ | |||
+ | ================================================================================ | ||
+ | begin 640 hires80.bin | ||
+ | M`!-, | ||
+ | MZ"#, | ||
+ | M^H7\F*``A/ | ||
+ | M1OUJ&& | ||
+ | MI? | ||
+ | MHB`& | ||
+ | MQE0F9" | ||
+ | MSQ-H$!DXJ0# | ||
+ | M$2`: | ||
+ | MM625# | ||
+ | MA5" | ||
+ | M" | ||
+ | MI03EBX4, | ||
+ | M`(4" | ||
+ | MA02E!64-A048I09E# | ||
+ | & | ||
+ | ` | ||
+ | end | ||
+ | ================================================================================ | ||
+ | begin 640 hires.demo | ||
+ | M`1PQ'& | ||
+ | M0DE.(@!!'& | ||
+ | M4BPS, | ||
+ | M' | ||
+ | L' | ||
+ | ` | ||
+ | end | ||
+ | ============================================================================== | ||
+ | ; | ||
+ | ;* " | ||
+ | ;* screen. | ||
+ | ;* * | ||
+ | ;* This package contains a couple of irregularities that I discovered | ||
+ | ;* while I was commenting it. I left them in rather than start all over, * | ||
+ | ;* since this package was written with a monitor rather than an assembler. | ||
+ | ; | ||
+ | |||
+ | ; | ||
+ | ;* package entry points | ||
+ | ; | ||
+ | |||
+ | .$1300 | ||
+ | .$1303 | ||
+ | .$1306 | ||
+ | .$1309 | ||
+ | .$130c | ||
+ | .$130f: $b3 ; | ||
+ | .$1310 | ||
+ | |||
+ | ; | ||
+ | ;* enter hires mode * | ||
+ | ; | ||
+ | |||
+ | .$1311 | ||
+ | .$1313 | ||
+ | .$1316 | ||
+ | .$1318 | ||
+ | .$131a | ||
+ | .$131d | ||
+ | .$131f | ||
+ | .$1321 | ||
+ | .$1324 | ||
+ | .$1326 | ||
+ | .$1328 | ||
+ | .$132b | ||
+ | .$132c | ||
+ | .$132f | ||
+ | .$1331 | ||
+ | .$1334 | ||
+ | .$1336 | ||
+ | .$1338 | ||
+ | .$133b | ||
+ | .$133d | ||
+ | .$133f | ||
+ | .$1341 | ||
+ | .$1344 | ||
+ | .$1345 | ||
+ | .$1347 | ||
+ | |||
+ | ; | ||
+ | ;* exit hires mode * | ||
+ | ; | ||
+ | |||
+ | .$1348 | ||
+ | .$134b | ||
+ | .$134d | ||
+ | .$1350 | ||
+ | .$1352 | ||
+ | .$1354 | ||
+ | |||
+ | ; | ||
+ | ;*calculate the bitmap byte address and bit value for pixel given x=.AX,y=.Y * | ||
+ | ; | ||
+ | |||
+ | .$1357 | ||
+ | .$1359 | ||
+ | .$135b | ||
+ | .$135c | ||
+ | .$135e | ||
+ | .$1360 | ||
+ | .$1361 | ||
+ | .$1363 | ||
+ | .$1364 | ||
+ | .$1366 | ||
+ | .$1367 | ||
+ | .$1369 | ||
+ | .$136b | ||
+ | .$136d | ||
+ | .$136e | ||
+ | .$1370 | ||
+ | .$1371 | ||
+ | .$1373 | ||
+ | .$1374 | ||
+ | .$1376 | ||
+ | .$1377 | ||
+ | .$1379 | ||
+ | .$137b | ||
+ | .$137d | ||
+ | .$137f | ||
+ | .$1381 | ||
+ | .$1382 | ||
+ | .$1384 | ||
+ | .$1385 | ||
+ | .$1387 | ||
+ | .$1388 | ||
+ | .$1389 | ||
+ | .$138b | ||
+ | .$138d | ||
+ | .$138f | ||
+ | .$1391 | ||
+ | .$1393 | ||
+ | .$1395 | ||
+ | .$1397 | ||
+ | .$1398 | ||
+ | .$139b | ||
+ | .$139d | ||
+ | |||
+ | ; | ||
+ | ;* bit value table * | ||
+ | ; | ||
+ | |||
+ | .$139e: $80 $40 $20 $10 ;bit values stored left to right | ||
+ | .$13a2: $08 $04 $02 $01 | ||
+ | |||
+ | .$13a6 | ||
+ | .$13a7 | ||
+ | |||
+ | ; | ||
+ | ;* plot pixel at x=.AX, y=.Y on bitmap screen | ||
+ | ; | ||
+ | |||
+ | .$13a8 | ||
+ | .$13ab | ||
+ | .$13ad | ||
+ | .$13af | ||
+ | .$13b2 | ||
+ | .$13b4 | ||
+ | .$13b5 | ||
+ | .$13b8 | ||
+ | .$13bb | ||
+ | .$13bd | ||
+ | .$13be | ||
+ | .$13c0 | ||
+ | .$13c2 | ||
+ | .$13c5 | ||
+ | .$13c7 | ||
+ | .$13c8 | ||
+ | .$13cb | ||
+ | .$13cc | ||
+ | |||
+ | ; | ||
+ | ;* perform the unsigned 32-bit divide with 16-bit denominator (bottom) | ||
+ | ;* [$63 $62 $61 $60] is the numerator (top) * | ||
+ | ;* [$51 $50] is the denominator (bottom) | ||
+ | ;* [$67 $66 $65 $64] is the quotient (result) | ||
+ | ;* [$54 $53 $52] is the remainder | ||
+ | ; | ||
+ | |||
+ | .$13cf | ||
+ | .$13d1 | ||
+ | .$13d3 | ||
+ | .$13d5 | ||
+ | .$13d7 | ||
+ | |||
+ | .$13d9 | ||
+ | .$13db | ||
+ | .$13dd | ||
+ | |||
+ | .$13df | ||
+ | .$13e1 | ||
+ | .$13e3 | ||
+ | .$13e5 | ||
+ | .$13e7 | ||
+ | .$13e9 | ||
+ | .$13eb | ||
+ | .$13ed | ||
+ | .$13ef | ||
+ | .$13f1 | ||
+ | .$13f3 | ||
+ | .$13f5 | ||
+ | .$13f7 | ||
+ | .$13f9 | ||
+ | .$13fb | ||
+ | .$13fd | ||
+ | .$13fe | ||
+ | .$1400 | ||
+ | .$1402 | ||
+ | .$1404 | ||
+ | .$1406 | ||
+ | .$1408 | ||
+ | .$140a | ||
+ | .$140c | ||
+ | .$140e | ||
+ | .$1410 | ||
+ | .$1412 | ||
+ | .$1414 | ||
+ | ; cannot happen in this application. | ||
+ | .$1416 | ||
+ | .$1417 | ||
+ | .$1419 | ||
+ | |||
+ | ; | ||
+ | ;* get the absolute value of the 2's comp number in .AY -> .AY * | ||
+ | ; | ||
+ | |||
+ | .$141a | ||
+ | .$141c | ||
+ | .$141e | ||
+ | .$1420 | ||
+ | .$1421 | ||
+ | .$1423 | ||
+ | .$1425 | ||
+ | .$1427 | ||
+ | .$1428 | ||
+ | .$142a | ||
+ | .$142c | ||
+ | .$142e | ||
+ | .$142f | ||
+ | .$1430 | ||
+ | |||
+ | ; | ||
+ | ;* perform the fractional signed 32-bit divide | ||
+ | ; | ||
+ | |||
+ | .$1431 | ||
+ | .$1432 | ||
+ | .$1434 | ||
+ | .$1436 | ||
+ | .$1438 | ||
+ | .$143b | ||
+ | .$143c | ||
+ | .$143e | ||
+ | .$143f | ||
+ | .$1441 | ||
+ | .$1443 | ||
+ | .$1445 | ||
+ | .$1447 | ||
+ | .$1449 | ||
+ | .$144b | ||
+ | .$144d | ||
+ | .$144f | ||
+ | .$1451 | ||
+ | .$1453 | ||
+ | .$1455 | ||
+ | .$1457 | ||
+ | |||
+ | ; | ||
+ | ;* get the X and Y plotting increments and the pixels-to-plot count * | ||
+ | ; | ||
+ | |||
+ | .$1458 | ||
+ | .$145a | ||
+ | .$145c | ||
+ | .$145f | ||
+ | .$1461 | ||
+ | |||
+ | .$1463 | ||
+ | .$1465 | ||
+ | .$1467 | ||
+ | .$146a | ||
+ | .$146c | ||
+ | |||
+ | .$146e | ||
+ | .$1470 | ||
+ | .$1472 | ||
+ | .$1474 | ||
+ | .$1476 | ||
+ | |||
+ | .$1478 | ||
+ | .$147a | ||
+ | .$147c | ||
+ | .$147e | ||
+ | .$1480 | ||
+ | .$1482 | ||
+ | .$1484 | ||
+ | .$1486 | ||
+ | .$1488 | ||
+ | .$148a | ||
+ | .$148c | ||
+ | .$148e | ||
+ | .$1491 | ||
+ | .$1493 | ||
+ | .$1495 | ||
+ | .$1497 | ||
+ | .$1498 | ||
+ | .$149a | ||
+ | .$149c | ||
+ | .$149e | ||
+ | .$14a0 | ||
+ | .$14a2 | ||
+ | .$14a4 | ||
+ | .$14a6 | ||
+ | .$14a8 | ||
+ | .$14aa | ||
+ | .$14ac | ||
+ | |||
+ | .$14ae | ||
+ | .$14af | ||
+ | .$14b1 | ||
+ | .$14b3 | ||
+ | .$14b5 | ||
+ | .$14b7 | ||
+ | .$14b9 | ||
+ | .$14bb | ||
+ | |||
+ | .$14bc | ||
+ | .$14be | ||
+ | .$14c0 | ||
+ | .$14c2 | ||
+ | .$14c4 | ||
+ | .$14c6 | ||
+ | .$14c8 | ||
+ | .$14ca | ||
+ | .$14cc | ||
+ | .$14ce | ||
+ | .$14d0 | ||
+ | .$14d2 | ||
+ | .$14d5 | ||
+ | .$14d7 | ||
+ | .$14d9 | ||
+ | .$14db | ||
+ | .$14dc | ||
+ | .$14de | ||
+ | ;------- | ||
+ | .$14e1 | ||
+ | .$14e4 | ||
+ | .$14e7 | ||
+ | ;------- | ||
+ | .$14ea | ||
+ | .$14ec | ||
+ | .$14ee | ||
+ | .$14f0 | ||
+ | .$14f2 | ||
+ | .$14f4 | ||
+ | .$14f6 | ||
+ | .$14f8 | ||
+ | .$14fa | ||
+ | .$14fc | ||
+ | .$14fe | ||
+ | |||
+ | ; | ||
+ | ;* main routine: draw line or set pixel cursor position | ||
+ | ; | ||
+ | |||
+ | .$1501 | ||
+ | .$1503 | ||
+ | .$1505 | ||
+ | .$1507 | ||
+ | .$1509 | ||
+ | |||
+ | .$150a | ||
+ | .$150c | ||
+ | .$150e | ||
+ | .$1510 | ||
+ | .$1512 | ||
+ | .$1514 | ||
+ | .$1516 | ||
+ | .$1517 | ||
+ | |||
+ | .$1519 | ||
+ | .$151a | ||
+ | .$151c | ||
+ | .$151e | ||
+ | .$1520 | ||
+ | .$1522 | ||
+ | .$1524 | ||
+ | |||
+ | .$1526 | ||
+ | .$1527 | ||
+ | .$1529 | ||
+ | .$152b | ||
+ | .$152d | ||
+ | .$152f | ||
+ | .$1531 | ||
+ | .$1533 | ||
+ | |||
+ | .$1535 | ||
+ | |||
+ | .$1538 | ||
+ | .$153a | ||
+ | .$153c | ||
+ | .$153e | ||
+ | .$1540 | ||
+ | .$1542 | ||
+ | .$1544 | ||
+ | .$1546 | ||
+ | .$1548 | ||
+ | .$154a | ||
+ | .$154c | ||
+ | .$154e | ||
+ | .$1550 | ||
+ | .$1552 | ||
+ | |||
+ | .$1554 | ||
+ | .$1556 | ||
+ | .$1558 | ||
+ | .$155a | ||
+ | .$155d | ||
+ | .$155f | ||
+ | .$1561 | ||
+ | .$1563 | ||
+ | .$1564 | ||
+ | .$1566 | ||
+ | .$1568 | ||
+ | .$156a | ||
+ | .$156c | ||
+ | .$156e | ||
+ | .$1570 | ||
+ | .$1572 | ||
+ | .$1574 | ||
+ | .$1576 | ||
+ | .$1578 | ||
+ | .$157a | ||
+ | .$157c | ||
+ | .$157d | ||
+ | .$157f | ||
+ | .$1581 | ||
+ | .$1583 | ||
+ | .$1585 | ||
+ | .$1587 | ||
+ | .$1589 | ||
+ | .$158b | ||
+ | .$158d | ||
+ | .$158f | ||
+ | .$1591 | ||
+ | .$1593 | ||
+ | .$1595 | ||
+ | .$1597 | ||
+ | .$1599 | ||
+ | .$159b | ||
+ | |||
+ | .$159e | ||
+ | .$15a0 | ||
+ | .$15a2 | ||
+ | .$15a4 | ||
+ | ============================================================================== | ||
+ | THE END | ||
+ | </ |
magazines/chacking1.txt · Last modified: 2015-04-17 04:34 by 127.0.0.1