6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 8:58 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Mon Mar 20, 2017 3:29 pm 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1429
Video noise... and pseudo random number generators.

Wanted to share an old but useless little gimmick:

Attachment:
c64_video_noise.jpg
c64_video_noise.jpg [ 18.97 KiB | Viewed 1810 times ]


192*96 pixels, black\white, ca. 20 frames per second, generated on a C64.

;---

While spending two months without internet because of a broken arm,
I eventually found the time to scrap my collection of ca. 400 3½-inch floppy disks.

One of the disk labels remembered me back to the time when we did some 80x86 assembly
coding in a "DOS environment" at tech school... back in 1997. As time goes by.

At some point, I had felt a little bit bored, and just for the fun of it I had tried
to generate something that looks a little bit like video noise on the PC screen
with 48 Bytes of machine code or such.

Luckily, I still had a version of that 20 years old code printed on paper,
and because I recently felt bored again, I couldn't resist to try an implementation on the C64.


Just to make things clear:
I never tried to write any 80x86 assembly code after 1997,
and I would like to keep it that way ! :lol:


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 3:30 pm 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1429
Now my old code for a DOS PC.

With a Win XP PC from 2010, the code still worked in a DOS box set to full screen mode.
I'm not sure if it still works for newer implementations of the PC... or Windows.

Code:
; MASM x86 DOS6.22 1997

STAPEL  SEGMENT STACK
        DW 64 DUP (?)
STAPEL  ENDS


HAUPT   SEGMENT
        ASSUME  CS:HAUPT;SS:STAPEL

        mov     ax,0006h        ;Video mode 640*200 graphics black\white
        int     10h
       
        mov     ax,0b800h       ;set segments
        mov     ds,ax
        mov     es,ax
        mov     ds:[0],ax       ;"seed" for random generator
        cld                     ;direction for stosw, not to get confused with 6502 CLD.

RAUSCH: xor     di,di           ;set pointers
        mov     cx,2000h
       
RAU1:   mov     ax,ds:[di]
        adc     bx,ax           ;"randomly" change pixels
        adc     ax,bx
        stosw
        loop    RAU1            ;screen completed ?

        mov     ah,2            ;read keyboard status
        int     16h
        and     al,0fh          ;CTRL,SHIFT or ALT pressed ?
        jz      RAUSCH          ;exit, if yes.

        mov     ax,0003h        ;Video mode 80*25 text
        int     10h
        mov     ah,4ch
        int     21h             ;end program.
;
HAUPT   ENDS
        END


Edit: fixed typo.


Last edited by ttlworks on Mon Mar 20, 2017 4:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 3:33 pm 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1429
Now for my attempt of making a C64 implementation.

Code would have been simpler when generating a 320*200 picture.

Problem is, that the speed breaks down to not much more than 6 frames per second
when the C64 has to generate a picture that big.

But the optical effect on the screen won't look nice for less than 20 frames
per second, so I decided to use a smaller picture for increasing speed.

Code:
;Quick & dirty C64 implementation
;only 192*96 pixels used

INIT
        LDA     #$00   ; background color
        STA     $D020
        STA     $D021

        LDA     $3B   ; 320*200 HiRes mode
        STA     $D011
        LDA     $18
        STA     $D018
;
        LDX     #$04   ; init color RAM
        LDA     #$00
        JSR     CLR

        LDX     #$20   ; init graphics RAM
        LDA     #$10
        JSR     CLR
;
NOISE
        LDA     #$7F   ; init pointer
        STA     $22
        LDA     #$26
        STA     $23
        LDX     #$0C
NO1
        LDY     #$C0
NO2
        ROR     A   ; the inner loop
        ADC     ($22),
        ROL     A
        STA     ($22),Y

        DEY
        BNE     NO2

        PHP
        PHA

        CLC
        LDA     $22
        ADC     #$40
        STA     $22
        LDA     $23
        ADC     #$01
        STA     $23

        PLA
        PLP

        DEX
        BPL     NO1

        LDY     $91     ;Run Stop ?
        BMI     NOISE
        JMP     ($FF81)   ;reset VIC2 and exit, if yes.


;----------------------------

CLR
        LDY     #$00
        STY     $22
        STX     $23
CLR1
        STA     ($22),Y
        INY
        BNE     CLR1

        INC     $23
        DEX
        BNE     CLR1
        RTS

;=============================
                 
.1000 A9 00 8D 20 D0 8D 21 D0
.1008 A9 3B 8D 11 D0 A9 18 8D
.1010 18 D0 A2 04 A9 10 20 50
.1018 10 A2 20 A9 00 20 50 10
.1020 A9 7F 85 22 A9 26 85 23
.1028 A2 0C A0 C0 6A 71 22 2A
.1030 91 22 88 D0 F7 08 48 18
.1038 A5 22 69 40 85 22 A5 23
.1040 69 01 85 23 68 28 CA 10
.1048 E1 A4 91 30 D3 6C 81 FF
.1050 A0 00 84 22 86 23 91 22
.1058 C8 D0 FB E6 23 CA D0 F6
.1060 60


That's all, have fun with tinkering. :)

BTW: I'm not sure if the 6502 assembly listing is without errors,
simply because it manually was generated from the raw machine code above.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 4:52 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
ttlworks wrote:
While spending two months without internet because of a broken arm,
I eventually found the time to scrap my collection of ca. 400 3½-inch floppy disks.

I, too, have a collection of old floppies which needs to be sorted through. But I hope to accomplish this without first breaking my arm! :shock: :roll:

Welcome back, Dieter! Glad to hear you're okay!

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 6:46 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
Dr Jefyll wrote:
I, too, have a collection of old floppies which needs to be sorted through. But I hope to accomplish this without first breaking my arm! :shock: :roll:

I never knew that old floppies were so heavy. :shock:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 7:16 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1382
Well, I weighed a group of 10- 3.5-inch floppies, 212 grams, or about 21.2 grams per floppy. Lifting 400 of them would be 8480 grams, or 8.48Kg or about 18.66 pounds. Unless his count is off by a lot, I don't really see any broken bones :mrgreen:

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 7:24 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
floobydust wrote:
Well, I weighed a group of 10- 3.5-inch floppies, 212 grams, or about 21.2 grams per floppy. Lifting 400 of them would be 8480 grams, or 8.48Kg or about 18.66 pounds.

It figures that someone would figure out tedious minutia such as how much a pile of floppy disks would weigh. :lol:

Quote:
Unless his count is off by a lot, I don't really see any broken bones :mrgreen:

I'd be more concerned about having 400 floppies piled so high the ceiling fan is batting them around the house. :shock: More likely, Dieter's wife was upset with him and smacked him in the arm with a cast iron skillet. :o

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 7:44 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1382
BigDumbDinosaur wrote:
floobydust wrote:
Well, I weighed a group of 10- 3.5-inch floppies, 212 grams, or about 21.2 grams per floppy. Lifting 400 of them would be 8480 grams, or 8.48Kg or about 18.66 pounds.

It figures that someone would figure out tedious minutia such as how much a pile of floppy disks would weigh. :lol:

Quote:
Unless his count is off by a lot, I don't really see any broken bones :mrgreen:

I'd be more concerned about having 400 floppies piled so high the ceiling fan is batting them around the house. :shock: More likely, Dieter's wife was upset with him and smacked him in the arm with a cast iron skillet. :o


Haha... well, you sorta asked for this one:

Said stack of 10 floppies are about 33.4mm thick, so 400 of them would be about 1.336 meters high, or 52.6 inches... bottom line, he's going to need a lot more floppies before they hit the fan!

Also, hardly tedious... took barely a minute!

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 20, 2017 9:24 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
floobydust wrote:
Also, hardly tedious... took barely a minute!

Glad someone has time to seek out these obscure bits of information. :lol:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 21, 2017 11:10 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 324
192x96 is the same number of pixels as a 24x12 block of characters, which is 288 of them. 256 isn't much lower. So... fill the screen with 256 different characters in some random pattern (you don't want any regularity in the layout, but you also don't want the duplicates of one character to occur too close together) and fill their definitions with your random numbers. Voila! A full screen of 20Hz snow.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 21, 2017 10:23 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 275
Location: Placerville, CA
John West wrote:
192x96 is the same number of pixels as a 24x12 block of characters, which is 288 of them. 256 isn't much lower. So... fill the screen with 256 different characters in some random pattern (you don't want any regularity in the layout, but you also don't want the duplicates of one character to occur too close together) and fill their definitions with your random numbers. Voila! A full screen of 20Hz snow.

Yeah, that was my thought. Lay out the character map in some pattern that's irregular enough to not break the effect, and you can generate a much smaller amount of noise and still give essentially the same effect, for purposes of human perception.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 24, 2017 12:10 am 
Offline

Joined: Mon Feb 20, 2012 1:46 pm
Posts: 25
Location: America
That's very fast for what you're doing. I hate to say this, but I've seen demos with video noise, and I'm pretty sure they just set the sound chip to produce noise and read the waveform register. You can do this in realtime and fill most of the screen with noise.

The sid chip does a 23 bit lfsr generator in hardware.
http://www.oxyron.de/html/registers_sid.html


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 24, 2017 8:06 am 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1429
@Jeff: thanks for the warm welcome. I'm still a bit slow with typing... might be getting better in half a year or so.

@repose: when spending some more thoughts on this, I'd say you are right about that using the SID LFSR would be a better approach for generating noise on the screen.
Thanks for telling me.

Anyhow, out of sentimental reasons I just wanted to know how that old piece of x86 code performs when getting ported to a ca. 1MHz 6502.
I somehow just never found the time to make a try during the past 20 years. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: